Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with Special Characters in WixSharp Bootstrapper Custom BA after Upgrading from Wix3 to Wix4 #1736

Closed
AwesomeM4rc opened this issue Jan 31, 2025 · 6 comments

Comments

@AwesomeM4rc
Copy link

AwesomeM4rc commented Jan 31, 2025

Hello 🙂

I have a problem after updating my WixSharp Bootstrapper from Wix3 to Wix4.

In Wix 3, it was possible to use © for the copyright. However, in Wix 4, when using ©, I get the following error:

WIX0104: Not a valid source file; detail: Invalid character in the given encoding. Line 2, position 39. (The position of the © in the .wxs)

Is there a way to get around this? I also encounter this problem when using characters like ä, ü, and so on.

I replicated the error with the WixSharp Boostrapper Custom BA (Wix4):

public class Program
{
    private static void Main()
    {
        // If you are using WiX5 tools then your Custom BA needs to be built as a separate assembly because WiX5 uses a completely different hosting model.
        // See this sample for WiX5 Custom BA: https://github.com/oleg-shilo/wixsharp/tree/master/Source/src/WixSharp.Samples/Wix%23%20Samples/Bootstrapper/WiX5-Spike/WixToolset.WixBA
        WixTools.SetWixVersion(Environment.CurrentDirectory, "4.0.6");

        WixTools.WixExtensionsDir = "%userprofile%\\.nuget\\packages".ExpandEnvVars();
        WixExtension.NetFx.PreferredVersion = "4.0.6";
        WixExtension.Bal.PreferredVersion = "4.0.6";
        WixExtension.Util.PreferredVersion = "4.0.6";
        WixExtension.UI.PreferredVersion = "4.0.6";

        var productMsi = BuildMsi();

        var bootstrapper = new Bundle("MyProduct",
            new MsiPackage(productMsi)
            {
                Id = "MyProductPackageId",
                DisplayInternalUI = true
            });

        bootstrapper.Copyright = @"© My Company 2016";
        bootstrapper.Version = new Version("1.0.0.0");
        bootstrapper.UpgradeCode = new Guid("25f7a758-751a-4aeb-8ccd-742a9fd35867");

        bootstrapper.Application = new ManagedBootstrapperApplication("%this%");

        bootstrapper.Build("MyProduct.exe");
    }

    private static string BuildMsi()
    {
        var project = new Project("MyProduct",
            new Dir(@"%ProgramFiles%\My Company\My Product",
                new File("Program.cs")));

        project.GUID = new Guid("25f7a758-751a-4aeb-8ccd-742a9fd35867");

        return project.BuildMsi();
    }
}

Any help or suggestions would be greatly appreciated!

@Torchok19081986
Copy link

Torchok19081986 commented Jan 31, 2025

Hallo, i dont know, but i found this one on wix toolset website. https://wixtoolset.org/docs/tools/preprocessor/#escaping
It seems you have a germany letters in your BA Installer. Standard BA language is en-us. AFAIK you can change it. Maybe this helps. There is sample in samples folder for language in BA Installer. Try it.
Stackoverflow : https://stackoverflow.com/questions/11070209/inserting-a-copyright-registered-symbol-in-the-installer-using-wix
looks like your trouble here.

@AwesomeM4rc
Copy link
Author

AwesomeM4rc commented Jan 31, 2025

Hey Torchok!

Thanks for the input and yes it's german based :) I found a way with WixSharp to get it working. I just re-save the .wxs file in the encoding UTF-8 (after it was saved - bootstrapper.WixSourceSaved).

public class Program
{
    private static void Main()
    {
        // If you are using WiX5 tools then your Custom BA needs to be built as a separate assembly because WiX5 uses a completely different hosting model.
        // See this sample for WiX5 Custom BA https://github.com/oleg-shilo/wixsharp/tree/master/Source/src/WixSharp.Samples/Wix%23%20Samples/Bootstrapper/WiX5-Spike/WixToolset.WixBA
        WixTools.SetWixVersion(Environment.CurrentDirectory, "4.0.6");

        WixTools.WixExtensionsDir = "%userprofile%\\.nuget\\packages".ExpandEnvVars();
        WixExtension.NetFx.PreferredVersion = "4.0.6";
        WixExtension.Bal.PreferredVersion = "4.0.6";
        WixExtension.Util.PreferredVersion = "4.0.6";
        WixExtension.UI.PreferredVersion = "4.0.6";

        var productMsi = BuildMsi();

        var bootstrapper =
            new Bundle("MyProdÜÄct",
                new MsiPackage(productMsi)
                {
                    Id = "MyProductPackageId",
                    DisplayInternalUI = true
                });

        bootstrapper.Copyright = @"® My Company 2016";
        bootstrapper.Version = new Version("1.0.0.0");
        bootstrapper.UpgradeCode = new Guid("25f7a758-751a-4aeb-8ccd-742a9fd35867");

        bootstrapper.Application = new ManagedBootstrapperApplication("%this%");

        bootstrapper.WixSourceSaved += BootstrapperOnWixSourceSaved;

        bootstrapper.Build("MyProduct.exe");
    }

    private static void BootstrapperOnWixSourceSaved(string filename)
    {
        var fileContent = System.IO.File.ReadAllText(filename, Encoding.Default);

        System.IO.File.WriteAllText(filename, fileContent, Encoding.UTF8);
    }

    private static string BuildMsi()
    {
        var project = new Project("MyProduct",
            new Dir(@"%ProgramFiles%\My Company\My Product",
                new File("Program.cs")));

        project.GUID = new Guid("25f7a758-751a-4aeb-8ccd-742a9fd35867");

        return project.BuildMsi();
    }
}

Result:

Image


using (var sw = new IO.StreamWriter(file, false, Encoding.Default))

It appears that the compiler consistently utilizes Encoding.Default to write the initial .wxs file.
It might be beneficial to provide an option to modify this setting?

oleg-shilo added a commit that referenced this issue Feb 1, 2025
@oleg-shilo
Copy link
Owner

The project.Encoding is your friend. Though unfortunately, it's only available for MSI projects but not for Bundle (this property was introduced before Bubdle support).
I just extended it to be available for Bundle too.

The fix will be available in the very next release.

oleg-shilo added a commit that referenced this issue Feb 1, 2025
- #1736: Issue with Special Characters in WixSharp Bootstrapper Custom BA after Upgrading from Wix3 to Wix4
- Improved positioning of the background images for WPF UI Dialogs
- WIP: Added support for modern style folder selection dialog (triggered by #1734 discussion)
- Added a more convenient option to play dialogs in demo mode during development
@oleg-shilo
Copy link
Owner

Done.
Please update to v2.5.0.0.
You can set the encoding now via bundle.Encoding

@AwesomeM4rc
Copy link
Author

Hi Oleg,

Thank you for the fast package update! It works perfectly. 😊

Also, thanks to @Torchok19081986 for your valuable input.

I especially appreciate the change to UTF-8 encoding for the bundle. This improvement means I no longer need to specify anything about the encoding inside the bootstrapper, which is fantastic.

Best regards,
Marc

@oleg-shilo
Copy link
Owner

...appreciate the change to UTF-8...

Yes, indeed it wasn't the best choice of the default value. Glad the problem has been discovered and fixed.

And indeed thank you @@Torchok19081986 for attending this ticket.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants