Skip to content

Instantly share code, notes, and snippets.

@dasMulli
Created March 14, 2017 22:19
Show Gist options
  • Save dasMulli/69f5303aa79a8cd4060e44891c90fd2d to your computer and use it in GitHub Desktop.
Save dasMulli/69f5303aa79a8cd4060e44891c90fd2d to your computer and use it in GitHub Desktop.
Sample CI build definition using MSBuild
<Project>
<ItemGroup>
<Solution Include="*.sln" />
<PublishProject Include="XXX.Mvc\XXX.Mvc.csproj" />
<TestProject Include="**\*.Test*.*proj" Exclude="XXX.Tests.Shared\XXX.Tests.Shared.csproj" />
</ItemGroup>
<Target Name="Build">
<MSBuild Projects="@(Solution)" Targets="Restore" ContinueOnError="ErrorAndStop" UnloadProjectsOnCompletion="true" UseResultsCache="false" />
<MSBuild Projects="@(PublishProject)" Targets="Publish" Properties="Configuration=Release" ContinueOnError="ErrorAndContinue" />
<MSBuild Projects="@(TestProject)" Targets="VSTest" Properties="VSTestLogger=trx" ContinueOnError="ErrorAndContinue" />
</Target>
</Project>
@rainersigwald
Copy link

Note that running Restore and Build (implied by Test) in the same invocation isn't guaranteed to work--Restore can bring down new MSBuild .props and .targets files from the packages, but they won't be seen by Build because the project XML has already been cached.

@dasMulli
Copy link
Author

@rainersigwald so far UnloadProjectsOnCompletion="true" on the initial Targets="Restore" call has worked great, I even use NuGet packages that bring in build targets (https://github.com/dasMulli/SimpleGitVersion to be specific) - and it works when starting from a fresh clone that hasn't been restored.

@dasMulli
Copy link
Author

dasMulli commented May 9, 2017

It works because the msbuild calls are done with different properties, which causes a forced re-evaluation of the project files.

@jeremysimmons
Copy link

wow @dasMulli that's some pretty epic MSBuild voodoo.

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