Simplified MSBuild-based build scripts empowered by NuGet
CoreBuild leverages a feature called MSBuild Sdks, which were introduced very recently in
MSBuild 15.0 (Visual Studio 15.6+ in particular) and allows simplified MSBuild project authoring.
CoreBuild provides the necessary targets and properties to enable NuGet
support in your build scripts.
Just create your SDK-style MSBuild script project as follows:
<Project Sdk="CoreBuild/1.0.0-alpha"> <!-- Your properties, targets and PackageReference items here --> </Project>
NOTE: Consider making it CoreBuild Standard compliant so that your contributors can easily know what steps are necessary to clone, configure, build, test and run your project.
Alternatively, you can download and boostrap the project in a single
command by running the following on the folder you intend to create
build.proj file, typically your repository root.
From a PowerShell command prompt:
curl http://corebuild.io/build.proj -o build.proj; msbuild /nologo /v:m /t:configure; msbuild /nologo /t:help
From a regular command prompt using curl.exe:
curl -k -L http://corebuild.io/build.proj -o build.proj && msbuild /nologo /v:m /t:configure && msbuild /nologo /t:help
This will download the sample project,
/t:Configure to restore packages, and run the
/t:Help target so you can see how documentation
can be authored and rendered nicely from your build project.
CoreBuild provides a basic starting point
for writing build scripts using MSBuild taking advantage of the newest features of MSBuild 15+
and NuGet packages for consuming reusable MSBuild props, targets and tasks which is also
CoreBuild Standard compliant.
CoreBuild also provides automatic targets and properties help via the the CoreBuild.Help package, which is automatically referenced by the SDK.
Writing MSBuild targets is getting considerably more convenient as MSBuild is evolving in v15.0 and beyond. Together with the built-in support for NuGet package restore from MSBuild, the combination is now much more powerfull and allows for more concise and readable build scripts.
Examples of the increased power allowed by this new combination:
Levaraging a NuGet package natively for doing versioning:
<ItemGroup> <PackageReference Include="GitInfo" Version="*" /> </ItemGroup> <Target Name="Build" DependsOnTargets="GitVersion"> ... </Target>
This brings the latest & greatest version of GitInfo for versioning the built artifacts, for example. Note the concise notation for item metadata (
Versionattribute above) as well as the floating dependency version.
Levaraging a NuGet package natively for detecting
<ItemGroup> <PackageReference Include="MSBuilder.IsXBuild" Version="*" /> </ItemGroup> <Target Name="Build"> <Error Condition="'$(IsXBuild)' == 'true'" Text="This build script requires MSBuild." /> ... </Target>
There are many more such reusable build blocks at MSBuilder.
Levaraging xunit NuGet package natively for running tests:
<ItemGroup> <PackageReference Include="xunit.runner.msbuild" Version="2.2.0" /> </ItemGroup> <ItemGroup> <TestAssembly Include="src\**\*Tests*.dll" /> </ItemGroup> <Target Name="Test"> <xunit Assemblies="@(TestAssembly)" /> </Target>
In order to enable package restore from MSBuild, the
CoreBuild SDK opts-in to the NuGet 4.0
features available in VS2017 for s"SDK Style" MSBuild projects, by specifying
NuGet will automatically generate the restore artifacts in the
.nuget folder alongside your
build.proj, which is typically ignored by default in source control (i.e. via
\root - build.proj \.nuget - [nuget restore artifacts here, updated by /t:Restore]
Sdk.targets then import the generated targets from NuGet, allowing
build.proj project to readily consume their artifacts.
looks quite clean:
<Project Sdk="CoreBuild/[VERSION]" DefaultTargets="Build"> <ItemGroup> <!-- Some PackageReferences for reusable MSBuild "scriptlets"... --> </ItemGroup> <Target Name="Build"> ... </Target> <Target Name="Clean"> ... </Target> <Target Name="Rebuild" DependsOnTargets="Clean;Build" /> </Project>