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

Cannot add environment variables to project object if only merge modules are present. #2

Closed
ninjamast3r opened this issue Dec 7, 2016 · 2 comments
Assignees
Labels

Comments

@ninjamast3r
Copy link

I'm having issues building an msi out of several merge modules, while at the same time adding an environment variable to the project object. Here's what I'm trying to do:

static void Main(string[] args)
        {
            var feature = new Feature("Complete");
            var project = new Project("testproject",
                new Dir(@"%ProgramFiles%\somedir",
                    new Merge(feature, @"D:\path\merge.msm")),
                new EnvironmentVariable("foo", "bar"));

            project.DefaultFeature = feature;
            project.Platform = Platform.x64;

            project.PreserveTempFiles = true;

            project.BuildMsi();
        }

If I run this code, I end up with the following error:

Unhandled Exception: System.InvalidOperationException: Sequence contains no elements
at System.Linq.Enumerable.First[TSource](IEnumerable1 source) at WixSharp.Compiler.GetTopLevelDir(XElement product) at WixSharp.Compiler.ProcessEnvVars(Project wProject, Dictionary2 featureComponents, List`1 defaultFeatureComponents
, XElement product)
at WixSharp.Compiler.GenerateWixProj(Project project)
at WixSharp.Compiler.BuildWxs(Project project, String path, OutputType type)
at WixSharp.Compiler.BuildWxs(Project project, OutputType type)
at WixSharp.Compiler.Build(Project project, String path, OutputType type)
at WixSharp.Compiler.Build(Project project, OutputType type)
at WixSharp.Compiler.BuildMsi(Project project)
at WixSharp.Project.BuildMsi(String path)
at BlastZone.Program.Main(String[] args) in C:\Users\user\Documents\Visual Studio 2015\Projects\BlastZone\BlastZone
\Program.cs:line 27

However, I don't get this error if I add a File object like so:

static void Main(string[] args)
        {

            var feature = new Feature("Complete");
            var project = new Project("testproject",
                new Dir(@"%ProgramFiles%\somedir",
                    new File(@"C:\Public\somefile.txt"),
                    new Merge(feature, @"D:\path\merge.msm")),
                new EnvironmentVariable("foo", "bar"));

            project.DefaultFeature = feature;
            project.Platform = Platform.x64;

            project.PreserveTempFiles = true;

            project.BuildMsi();
        }

I've been able to work around the issue be modifying the WiX directly, so I know this it's possible to do what I'm seeking. Is the requirement on a File object in the install Directory intended, or is it a bug?

Thanks.

@oleg-shilo oleg-shilo added the bug label Dec 9, 2016
@oleg-shilo oleg-shilo self-assigned this Dec 9, 2016
@oleg-shilo
Copy link
Owner

Thank you for an excellent test case. It is a bug in Wix#.
The fix is on the way

@oleg-shilo
Copy link
Owner

Fixed in the Release v1.2
You can get the update from the latest NuGet

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

No branches or pull requests

2 participants