Wixsharp: %ProgramData% environment variable not recognized

Created on 29 Oct 2018  路  3Comments  路  Source: oleg-shilo/wixsharp

I'm trying to copy some files to a specific folder inside %ProgramData% but it fails with the following error:

Unhandled Exception: WixSharp.ValidationException: WixSharp.Dir.Name is set to unknown environment constant '%ProgramData%'.
2>  For the list of supported constants analyze WixSharp.Compiler.EnvironmentConstantsMapping.Keys.
2>     at WixSharp.ProjectValidator.Validate(Project project)
2>     at WixSharp.Compiler.GenerateWixProj(Project project)
2>     at WixSharp.Compiler.BuildWxs(Project project, String path, OutputType type)
2>     at WixSharp.Compiler.BuildWxs(Project project, OutputType type)
2>     at WixSharp.Compiler.Build(Project project, String path, OutputType type)
2>     at WixSharp.Compiler.Build(Project project, OutputType type)
2>     at UploadServiceInstaller.Setup.Main() in E:\Work\Doosan\Repos\Dev\Analytics\UploadServiceInstaller\Setup.cs:line 64

This is what I'm doing:

ManagedProject project =
    new ManagedProject($"{CompanyName} {ProductName}",
        new InstallDir($@"%ProgramFiles%\{CompanyName}\{ProductName}",
            new Files(@"bin\BuildFiles\*.*",
                f => f.EndsWith(".exe") ||
                      f.EndsWith(".config") ||
                      f.EndsWith(".dll"))),
        new Dir($@"%ProgramData%\{CompanyName}\{ProductName}",
            new WixSharp.File(@"bin\BuildFiles\Configuration\UploadService.config")));

WixSharp.Compiler.EnvironmentConstantsMapping doesn't exist.

question

Most helpful comment

Digging around in the documentation and the code I found that I can just do:

Dir programData = new Dir(
                        @"CommonAppDataFolder\Company\Product",
                        new WixSharp.File(@"path\to\some\file"));

And CommonAppDataFolder gets translated to %ProgramData%.

All 3 comments

%PpogramData% is not one of the supported WiX constants. Use the following code to list the constants that are supported:
C# Compiler.GetMappedWixConstants(true).ForEach(Console.WriteLine);

If it is one of the newer WiX features, which is not covered by WixSharp then you can specify its name as is, without enclosing it into % character pair.

I had same issue, i figured out, that %programmdata% is C:\ProgrammData and get with Environment.SpecialFolder Enum and Programmdata is CommonApplicationData results in same path like %programmdata%. Try it with this.

Digging around in the documentation and the code I found that I can just do:

Dir programData = new Dir(
                        @"CommonAppDataFolder\Company\Product",
                        new WixSharp.File(@"path\to\some\file"));

And CommonAppDataFolder gets translated to %ProgramData%.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ltemimi picture ltemimi  路  5Comments

yfnfif picture yfnfif  路  3Comments

Eagle3386 picture Eagle3386  路  6Comments

Chrissyoung1223 picture Chrissyoung1223  路  5Comments

ayman-eltemsahi picture ayman-eltemsahi  路  4Comments