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

Modify MS Build task to include configuration and platform parameters #1014

Closed
Davidvanluijk opened this issue Jul 5, 2021 · 14 comments
Closed

Comments

@Davidvanluijk
Copy link

Davidvanluijk commented Jul 5, 2021

In the wixsharp nuget package the build task does not pass on parameters of the build. This prevents usecases as building an installer for both debug and release or for different CPU architectures. I stopped using the task from wixsharp all together and copied my own task in the project instead.

This is the task that I'm using:

  <Target Name="MSIAuthoring" AfterTargets="AfterBuild">
    <Message Importance="high" Text="Building MSI" />
    <Exec Command="&quot;$(TargetPath)&quot; &quot;/MSBUILD:$(ProjectName)&quot; /WIXBIN:$(WixExtDir) /Configuration:$(Configuration) /Platform:$(Platform)" WorkingDirectory="$(ProjectDir)" />
  </Target>

This allows me to set the outputpath of the installer to something specific for the configuration/platform.

Can these parameters be added to the task in the wixsharp package?

@oleg-shilo
Copy link
Owner

Yes it is a good idea.
Though what is the rationale behind the change &quot;/WIXBIN:$(WixBinPackage)&quot;" into /WIXBIN:$(WixExtDir) ?

@Davidvanluijk
Copy link
Author

Davidvanluijk commented Jul 5, 2021

I forgot I modified that variable, but I just checked what happens if I use WixBinPackage: "Unhandled Exception: WixSharp.WixSharpException: WiX binaries cannot be found." I'm using the wix nuget package to avoid having to install Wix on all developer and buildserver PC's. maybe that's not expected by wixsharp?

@oleg-shilo
Copy link
Owner

That's interesting.

WixBinPackage is an environment variable. You can use it to pass the location of the Nuget package. Though it is an overwrite mechanism when the user can set this variable to bypass the default WiX location detection algorithm.

Are you saying that if you pass WixExtDir it works? If it is the case then I do not what this variable it. WixSharp never sets it.

If you doe not have WiX installed but only the package referenced by project then this it the path that WixSharp is using by default in WixBinLocator.FindWixBinLocation:

%userprofile%\.nuget\packages\wixsharp.wix.bin

So something is not working as expected in your case...

@Davidvanluijk
Copy link
Author

We have configured Nuget to use a different folder then the userprofile folder you indicate, that might cause the issue. I looked up the WixExtDir: it is defined in the wix.props file of the wix nuget package and points to the tools directory:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <WixInstallPath>$(MSBuildThisFileDirectory)..\tools</WixInstallPath>
    <WixExtDir>$(WixInstallPath)\</WixExtDir>

    <WixTargetsPath>$(WixInstallPath)\wix.targets</WixTargetsPath>
    <LuxTargetsPath>$(WixInstallPath)\lux.targets</LuxTargetsPath>

    <WixTasksPath>$(WixInstallPath)\WixTasks.dll</WixTasksPath>
    <WixSdkPath>$(WixInstallPath)\sdk\</WixSdkPath>
    <WixCATargetsPath>$(WixSdkPath)wix.ca.targets</WixCATargetsPath>
  </PropertyGroup>
</Project>

@Davidvanluijk
Copy link
Author

Is there a conclusion for this issue?

@oleg-shilo
Copy link
Owner

Sorry, I somehow missed your "We have configured Nuget..." message.

Thus this is what we have.

WixSharp implements the mechanism for passing a custom location of the WiX bin folder via MSBuild command parameters.

Currently it is done via an environment variable that is under complete user control.
The approach you are suggesting as an alternative relies on another environment variable that is set by a third-party software which may or may not be present on the build system. Meaning that this approach is actually less flexible than the current one. Thus if user simply copies all WiX folders manually there is no way to pass the location of this folder via msbuild if we implement WixExtDir.

Thus I am not sure I see a good reason to replace the current solution.

But where does it leave you? You can simply tunnel WixBinPackage to the WixExtDir on the system that has WiX toolset installed in the custom location:

set WixBinPackage=%WixExtDir%

either per process or globally and I expect it to address your issue.

@Davidvanluijk
Copy link
Author

Although I see why being dependent on another package it's property does not feel very reliable, it is not just a package: it is the main package you are dependent on. Is there a way to pass in the WinExtDir only if it is defined?

@oleg-shilo
Copy link
Owner

Absolutely, you can define it directly in your build script:

class Script
{
    static public void Main()
    {
        if (Environment.GetEnvironmentVariable("WixExtDir") != null)
            Compiler.WixLocation = Environment.GetEnvironmentVariable("WixExtDir");
    . . .

This is by far a more preferred way. More reliable and even debugable.

This approach is almost always overlooked.

@Davidvanluijk
Copy link
Author

It's not really an issue to add that line, but can't that line be added to WixBinLocator? That class seems to be full of options to try to find the wix binaries anyhow, it seems convient to add it there?

@oleg-shilo
Copy link
Owner

good idea,

I have my reservations against putting anything to the msbuild task as it is such a hard to control mechanizm.
However I am fully on board with extending the built-in routine that can be easily controlled or even disabled by the user.

oleg-shilo pushed a commit that referenced this issue Aug 4, 2021
@oleg-shilo
Copy link
Owner

Done.
David please have a look at this commit 0554c03 and let me know if you see any problems with it.

@Davidvanluijk
Copy link
Author

Looks good!

@oleg-shilo
Copy link
Owner

The change will be available in the very next release

@Davidvanluijk
Copy link
Author

Will the configuration and platform properties also be added to the MSBuild task (that was the original intent of this ticket) or is that for later?

oleg-shilo pushed a commit that referenced this issue Aug 9, 2021
oleg-shilo pushed a commit that referenced this issue Aug 14, 2021
* Added full UI for uninstalling from control panel. The feature can be enabled via `project.EnableUninstallFullUI(...)`
* Nsis Bootstrapper
  - Added support for Nsis Bootstrapper compression.
  - Added sample `BuildScriptWithCompressor` (Samples/Bootstrapper/NsisBootstrapper/setup.cs)
* Issue #1025: Add generated children of TypeLib to element
* Issue #1014: Modify MS Build task to include configuration and platform parameters
* Added support for `WixStandardBootstrapperApplication.HyperlinkSidebarLicense`.
* Issue #1023: Copy File Not working; Fixed misspelled field name
* Introduce logging options for UninstallFullUI feature
* Issue #1005: Request: Arm64 support
* Issue #1001: Fix null reference exception if SDK is located inside the wixlocation…
* Issue #999: Multiple windows services to single .exe
* Issue #995: IgnoreWildCardEmptyDirectories with 1.17.0 causes Wxs generation to never finish with multiple top-level dirs
* Fixed: Respect TargetFileName on OverwriteOnInstall option
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

2 participants