Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

@rainersigwald rainersigwald commented Apr 18, 2017

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

This comment has been minimized.

Copy link
Owner Author

@dasMulli dasMulli commented Apr 19, 2017

@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

This comment has been minimized.

Copy link
Owner Author

@dasMulli 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

This comment has been minimized.

Copy link

@jeremysimmons jeremysimmons commented Jun 6, 2017

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