Prevent MSI Authoring during run of MSBuild

Sep 4, 2015 at 7:30 PM
I've come across an issue recently while trying to write an MSBuild script for our build server that I'm about 90% sure is related to Wix#. When I run my build script on my development machine, everything works like expected, and the build succeeds. However, when I run on the build server, my script tries to run my program, which I wouldn't expect it to do during a build. I tracked it down further to this line during my build:
MSIAuthoring:
  Building MSI
  "C:\Program Files (x86)\Jenkins\workspace\Test Build\BuildArtifacts\MsiBuildTool.exe" "/MBSBUILD:MsiBuildTool"
Based on this question: https://wixsharp.codeplex.com/discussions/612463 I'm guessing it has something to do with cscs.exe being run. My questions are: 1) Is there a way to disable MSI Authoring, or a least set it so that it doesn't run my project's .exe files? and 2) If I can't disable MSI Authoring, do you know what properties I might need to set on my build server to make it run like it does on my local machine?

I've attached my build script for reference, just in case.
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="RunTests" 
         xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup>
    <BuildArtifactsDir Include="BuildArtifacts\"/>
    <SolutionFile Include="MsiBuildTool.sln"/>
    <NUnitConsole Include="C:\Program Files (x86)\NUnit 2.6.4\bin\nunit-console.exe"/>
    <UnitTestsDll Include="BuildArtifacts\MsiBuildToolUnitTests.dll"/>
    <TestResultsPath Include="BuildArtifacts\TestResults.xml"/>
  </ItemGroup>

  <PropertyGroup>
    <Configuration Condition="'$(Configuration)' == ''">Release</Configuration>
    <Platform Condition="'$(Platform)' == ''">Any CPU</Platform>
  </PropertyGroup>

  <Target Name="Init" DependsOnTargets="Clean">
    <MakeDir Directories="@(BuildArtifactsDir)"/>
  </Target>
  
  <Target Name="Clean">
    <RemoveDir Directories="@(BuildArtifactsDir)"/>
  </Target>

  <Target Name ="Compile" DependsOnTargets="Init">
    <MSBuild Projects="@(SolutionFile)"
             Targets ="Rebuild"
             Properties ="OutDir=%(BuildArtifactsDir.FullPath);Configuration=$(Configuration);Platform=$(Platform)"/>
  </Target>
  
  <Target Name="RunTests" DependsOnTargets="Compile">
    <Exec Command='"@(NUnitConsole)" @(UnitTestsDll) /xml=@(TestResultsPath)'/>
  </Target>
</Project>
Coordinator
Sep 6, 2015 at 3:24 AM
I assume you are using VS Wix# project to build MSI. If it is indeed the case then cscs.exe has nothing to do with this as it is only involved in the authoring without VS. In fact this way may be (in some cases) a more convenient approach for integrating with MSBuild.

When you are using VS with the project created from a proper Wix# template the actual authoring is triggered by the WixSharp targets imported by your project from the NuGet package. And the actual authoring process is in fact involves executing the freshly built assembly.

If you want to disable it then you can just remove importing this targets form the project file. If you just open the project file in Notepad then you will see the statements I am referring to.

You can read about the VS integration here:
https://wixsharp.codeplex.com/wikipage?title=Visual%20Studio%20Project%20Templates
https://wixsharp.codeplex.com/wikipage?title=Developer%27s%20Guide#_envintegration

And of course, since running the project assembly at the end of the build is not illegal for the MSBuild model, you can also execute the assembly not form project targets but from post-build events. You can also make the C# call project.BuildMsi() subject to environment condition (e.g. env var).
Sep 8, 2015 at 1:04 PM
As suggested, I disabled the target imports from the project by removing this line:
<Import Project="..\packages\WixSharp.1.0.22.3\build\WixSharp.targets" Condition="Exists('..\packages\WixSharp.1.0.22.3\build\WixSharp.targets')" />
Worked perfectly. Thanks.