Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.

Commit b87997a

Browse files
committed
Switch to using corebuild for build-time packages
This simplifies the build targets and integrates with built-in nuget restore capabilities in MSBuild 15+
1 parent 2c924c3 commit b87997a

5 files changed

Lines changed: 88 additions & 26 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ temp
1818
NuGet.exe
1919
packages
2020
project.lock.json
21+
.nuget
2122
*.nuget.props
2223
*.nuget.targets
2324

build.proj

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<Project ToolsVersion="14.0" DefaultTargets="All" InitialTargets="Configure" TreatAsLocalProperty="RootSuffix" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2+
<Project DefaultTargets="All" InitialTargets="Configure" TreatAsLocalProperty="RootSuffix" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="corebuild\corebuild.props" />
34
<Import Project="build.props" />
45

56
<PropertyGroup Condition="'$(IsCIBuild)' != 'true'">
@@ -28,6 +29,14 @@
2829
<TestProject Include="src\Build\**\*Tests.csproj" />
2930
</ItemGroup>
3031

32+
<ItemGroup>
33+
<PackageReference Include="GitInfo" Version="2.0.0" />
34+
<PackageReference Include="xunit.runner.console" Version="2.3.0-beta4-build3742" />
35+
<PackageReference Include="xunit.runner.msbuild" Version="2.2.0" />
36+
<PackageReference Include="OpenCover" Version="4.6.519" />
37+
<PackageReference Include="ReportGenerator" Version="2.4.5" />
38+
</ItemGroup>
39+
3140
<Target Name="All" DependsOnTargets="Build;Test;Package" />
3241

3342
<Target Name="Clean">
@@ -67,21 +76,20 @@
6776
<MakeDir Directories="$(Out)" Condition="!Exists('$(Out)')" />
6877

6978
<PropertyGroup>
70-
<XunitConsole>"$(PackagesPath)\xunit.runner.console\tools\xunit.console.exe"</XunitConsole>
79+
<XunitConsole>"$(XunitConsolePath)"</XunitConsole>
7180
<XunitOptions>$(XunitOptions) -html $(Out)\test.html -xml $(Out)\test.xml -parallel all -noshadow</XunitOptions>
7281
</PropertyGroup>
7382

7483
<Exec Command="$(XunitConsole) @(TestAssembly, ' ') $(XunitOptions)" ConsoleToMSBuild="true" />
7584
</Target>
7685

77-
<Target Name="Restore">
86+
<Target Name="AfterRestore" AfterTargets="Restore">
7887
<ItemGroup>
7988
<RestoreProject Include="src\Build\NuGet.Build.Packaging.Tests\Scenarios\given_a_library_with_non_nugetized_reference\b.sln" />
8089
<RestoreProject Include="src\Build\NuGet.Build.Packaging.Tests\Scenarios\given_a_multi_platform_solution\forms.sln" />
8190
<RestoreProject Include="src\Build\NuGet.Build.Packaging.Tests\Scenarios\given_a_library_with_json_dependencies\a.csproj" />
8291
<RestoreProject Include="src\Build\NuGet.Build.Packaging.Tests\Scenarios\given_a_packaging_project_with_netstandard\a.nuproj" />
8392
<RestoreProject Include="src\Build\NuGet.Build.Packaging.Tests\Scenarios\given_a_library_with_private_assets_reference\a.csproj" />
84-
8593
</ItemGroup>
8694

8795
<MSBuild Projects="@(Solution);@(TestProject);@(RestoreProject)" Targets="Restore" Properties="$(CommonBuildProperties)" />
@@ -123,16 +131,6 @@
123131
<Exec Command="start $(Out)\coverage\index.htm" />
124132
</Target>
125133

126-
<!-- Configure and restore initial targets and packages -->
127-
<Import Project="src\NuGet.Restore.targets" />
128-
<PropertyGroup>
129-
<GitInfoTargets>$(PackagesPath)\GitInfo\build\GitInfo.targets</GitInfoTargets>
130-
<XunitConsole>$(PackagesPath)\xunit.runner.console\tools\xunit.console.x86.exe</XunitConsole>
131-
<XunitBuildDir>$([System.IO.Path]::Combine('$(MSBuildThisFileDirectory)', '.nuget', 'packages', 'xunit.runner.msbuild', 'build'))</XunitBuildDir>
132-
<XunitProps>$([System.IO.Path]::Combine($(XunitBuildDir), 'xunit.runner.msbuild.props'))</XunitProps>
133-
<PendingRestore Condition=" !Exists('$(GitInfoTargets)') Or !Exists('$(XunitConsole)') Or !Exists('$(XunitProps)') ">true</PendingRestore>
134-
</PropertyGroup>
135-
<Import Project="$(XunitProps)" Condition="Exists('$(XunitProps)')"/>
136134
<Target Name="GitVersion">
137135
<PropertyGroup>
138136
<GitSemVerMajor>1</GitSemVerMajor>
@@ -141,32 +139,27 @@
141139
</PropertyGroup>
142140
</Target>
143141
<Import Project="src\PackageVersion.targets" />
144-
<Import Project="$(GitInfoTargets)" Condition="Exists('$(GitInfoTargets)')"/>
145142

146-
<Target Name="Configure" DependsOnTargets="DownloadNuGet;GetPackageVersion">
143+
<Target Name="Configure" DependsOnTargets="GetPackageVersion">
147144
<Message Importance="high" Text="*********************************************************************************************************************" />
148145
<Message Importance="high" Text="$([System.Environment]::CommandLine)" />
149146
<Message Importance="high" Text="*********************************************************************************************************************" />
150147

151-
<Exec Command='"$(NuGet)" Install "$(MSBuildThisFileDirectory)packages.config" -OutputDirectory "$(PackagesPath)" -ExcludeVersion -Verbosity quiet'
152-
StandardOutputImportance="low"
153-
Condition=" '$(PendingRestore)' == 'true' " />
154-
155-
<Error Text="Build script NuGet packages were missing and were just restored. Please run the build again." Condition=" '$(PendingRestore)' == 'true' and '$(target)' != 'Restore' "/>
156-
157148
<!-- Invoke GitVersion just like the project-level targets do -->
158-
<CallTarget Targets="GitInfoReport" Condition="'$(PendingRestore)' != 'true'" />
149+
<CallTarget Targets="GitInfoReport" Condition="'$(target)' != 'Restore'" />
159150
<!-- For now this is an informative version #, used to update CI -->
160-
<Message Text="Building version $(PackageVersion)" Importance="high" Condition="'$(PendingRestore)' != 'true'" />
151+
<Message Text="Building version $(PackageVersion)" Importance="high" Condition="'$(target)' != 'Restore'" />
161152

162153
<PropertyGroup>
163154
<GitInfoReportImportance>high</GitInfoReportImportance>
164155
</PropertyGroup>
165156

166157
<!-- Update AppVeyor build # to match the actual one being used -->
167158
<Exec Command="appveyor UpdateBuild -Version $(PackageVersion)"
168-
Condition=" '$(APPVEYOR)' == 'true' and '$(PendingRestore)' != 'true' "
159+
Condition=" '$(APPVEYOR)' == 'true' and '$(target)' != 'Restore'"
169160
ConsoleToMSBuild="true"
170161
ContinueOnError="WarnAndContinue" />
171162
</Target>
172-
</Project>
163+
164+
<Import Project="corebuild\corebuild.targets" />
165+
</Project>

corebuild/corebuild.props

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<!-- Instruct NuGet to perform a NETCore-like restore -->
5+
<TargetFramework>netcore50</TargetFramework>
6+
<!-- Instruct NuGet that we use PackageReference, rather than project.json -->
7+
<RestoreProjectStyle>PackageReference</RestoreProjectStyle>
8+
<!-- Specify a well-known usually ignored directory for the generated targets -->
9+
<RestoreOutputPath>$(MSBuildThisFileDirectory).nuget</RestoreOutputPath>
10+
<ETag>9f31d2c2a2dcddd79bfc28ddb5217663b761a17c</ETag>
11+
<CoreBuildPropsImported>true</CoreBuildPropsImported>
12+
</PropertyGroup>
13+
14+
<!-- NuGet generated targets -->
15+
<Import Project="$(RestoreOutputPath)\$(MSBuildProjectFile).nuget.g.props" Condition="Exists('$(RestoreOutputPath)\$(MSBuildProjectFile).nuget.g.props')" />
16+
</Project>

corebuild/corebuild.targets

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<!-- Import NuGet.targets for Restore -->
4+
<PropertyGroup>
5+
<NuGetRestoreTargets Condition="'$(NuGetRestoreTargets)'==''">$(VsInstallRoot)\Common7\IDE\CommonExtensions\Microsoft\NuGet\NuGet.targets</NuGetRestoreTargets>
6+
</PropertyGroup>
7+
<Import Condition="Exists('$(NuGetRestoreTargets)')" Project="$(NuGetRestoreTargets)" />
8+
<Import Condition="'$(CoreBuildPropsImported)' == ''" Project="corebuild.props" />
9+
10+
<Import Project="$(RestoreOutputPath)\$(MSBuildProjectFile).nuget.g.targets" Condition="Exists('$(RestoreOutputPath)\$(MSBuildProjectFile).nuget.g.targets')" />
11+
12+
<!-- Unfortunately, NuGet restore depends on this target for its _GenerateRestoreProjectReferencePaths target -->
13+
<Target Name="_SplitProjectReferencesByFileExistence" />
14+
15+
<Target Name="GetVsInstallRoot" Returns="$(VsInstallRoot)">
16+
<Message Importance="high" Text="$(VsInstallRoot)" />
17+
</Target>
18+
19+
<ItemGroup>
20+
<PackageReference Include="CoreBuild.Updater" Version="*">
21+
<PrivateAssets>All</PrivateAssets>
22+
</PackageReference>
23+
<PackageReference Include="MSBuilder.XmlPoke" Version="*">
24+
<PrivateAssets>All</PrivateAssets>
25+
</PackageReference>
26+
</ItemGroup>
27+
28+
<PropertyGroup>
29+
<ETag>cdac7d6eaa07b64767e32bcb207a7dbdce1caf07</ETag>
30+
</PropertyGroup>
31+
32+
<!-- If we're being imported from another project, import the update-all version of Update -->
33+
<Import Project="update.targets" Condition="'$(MSBuildProjectFullPath)' != '(MSBuildThisFileFullPath)' And '$(IsUpdating)' != 'true'" />
34+
</Project>

corebuild/update.targets

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<UpdateBaseUrl>https://raw.githubusercontent.com/kzu/corebuild/master/src/corebuild</UpdateBaseUrl>
5+
</PropertyGroup>
6+
<ItemGroup>
7+
<_Updatable Include="$(MSBuildThisFileDirectory)corebuild.props" />
8+
<_Updatable Include="$(MSBuildThisFileDirectory)corebuild.targets" />
9+
</ItemGroup>
10+
11+
<Target Name="Update" Returns="@(_Updated)">
12+
<MSBuild Projects="$(MSBuildProjectFullPath)"
13+
Targets="Update"
14+
Properties="UpdateTarget=%(_Updatable.FullPath);UpdateUrl=$(UpdateBaseUrl)/%(_Updatable.Filename)%(_Updatable.Extension);IsUpdating=true">
15+
<Output TaskParameter="TargetOutputs" ItemName="_Updated" />
16+
</MSBuild>
17+
</Target>
18+
</Project>

0 commit comments

Comments
 (0)