Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
CI build script for a mvc + Webpack SPA app
<Project DefaultTargets="Build">
<PropertyGroup>
<Configuration>Release</Configuration>
</PropertyGroup>
<ItemGroup>
<SolutionFile Include="*.sln" />
<PublishProject Include="src\My.Mvc.Project\My.Mvc.Project.csproj" />
<NpmTestProject Include="@(PublishProject)" />
</ItemGroup>
<Target Name="Restore">
<MSBuild Projects="@(SolutionFile)" Targets="Restore;NpmInstall" />
</Target>
<Target Name="Build" DependsOnTargets="BuildProjects;Publish;Test" />
<Target Name="_PrepareParameters">
<PropertyGroup>
<OutputBaseDir Condition="'$(BUILD_ARTIFACTSTAGINGDIRECTORY)' != ''">$(BUILD_ARTIFACTSTAGINGDIRECTORY)\</OutputBaseDir>
<OutputBaseDir Condition="'$(OutputBaseDir)' == ''">$(MSBuildThisFileDirectory)</OutputBaseDir>
<PublishBaseDir>$(OutputBaseDir)artifacts</PublishBaseDir>
<TestResultsBaseDir>$(OutputBaseDir)test-results</TestResultsBaseDir>
<BuildProperties>Configuration=$(Configuration)</BuildProperties>
</PropertyGroup>
</Target>
<Target Name="BuildProjects" DependsOnTargets="_PrepareParameters">
<MSBuild Projects="@(SolutionFile)" Targets="Build" Properties="$(BuildProperties)" />
</Target>
<Target Name="Publish" DependsOnTargets="_PrepareParameters">
<MSBuild Projects="@(PublishProject)" Targets="Publish" Properties="$(BuildProperties);PublishDir=$(PublishBaseDir)\%(PublishProject.Filename)" />
</Target>
<Target Name="Test" DependsOnTargets="NpmCiTest;VSTest" />
<Target Name="NpmCiTest" DependsOnTargets="_PrepareParameters">
<MSBuild Projects="@(NpmTestProject)" Targets="NpmCiTest" Properties="$(BuildProperties);TestResultsOutputPath=$(TestResultsBaseDir)\%(NpmTestProject.Filename)\" />
</Target>
<Target Name="VSTest" DependsOnTargets="_PrepareParameters">
<MSBuild Projects="@(SolutionFile)" Targets="VSTest" Properties="$(BuildProperties);VSTestLogger=trx%3BLogFileName=VSTestResults.trx;TestResultsBaseDir=$(TestResultsBaseDir)" />
</Target>
</Project>
<Project>
<Target Name="NpmInstall" Condition="Exists('package.json')">
<Exec Command="npm install" />
</Target>
<Target Name="NpmCiTest" Condition="Exists('package.json')">
<Exec Command="npm run ci-test" />
<ItemGroup Condition="'$(TestResultsOutputPath)' != ''">
<TestResultFiles Include="obj\karma-testresults\**" />
</ItemGroup>
<Copy SourceFiles="@(TestResultFiles)" DestinationFolder="$(TestResultsOutputPath)" Condition="'$(TestResultsOutputPath)' != ''" />
</Target>
<PropertyGroup Condition="'$(TestResultsBaseDir)' != ''">
<VSTestResultsDirectory>$(TestResultsBaseDir)\$(MSBuildProjectName)</VSTestResultsDirectory>
</PropertyGroup>
<Target Name="VSTestIfTTestProject">
<CallTarget Targets="VSTest" Condition="'$(IsTestProject)' == 'true'" />
</Target>
</Project>
@dasMulli

This comment has been minimized.

Copy link
Owner Author

@dasMulli dasMulli commented Jan 5, 2018

To be run with dotnet build ci-build.proj or msbuild /restore ci-build.proj

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