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

Commit 258ab17

Browse files
authored
Merge pull request #144 from kzu/vsts
Auto-push for versioned branches, improve TFS support
2 parents 09d2c92 + 10216e1 commit 258ab17

File tree

9 files changed

+112
-44
lines changed

9 files changed

+112
-44
lines changed

.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

GitInfo.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.1.0
1+
0.2.0-dev

appveyor.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ deploy:
2626
api_key:
2727
secure: 7MS5+XWaFchMXFqzgneQCqo9U0DlxiPXe/KWWUnbCBDEizVn06EjdQZkWu1gbNOJ
2828
on:
29-
# we only deploy to public NuGet gallery when tagging the repo
30-
appveyor_repo_tag: true
29+
branch: /v\d+\.\d+\.\d+/
3130

3231
nuget:
3332
project_feed: true

build.cmd

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ if /I "%1" == "/test" set MSBuildTarget=Test&&shift&& goto :ParseArguments
2121
if /I "%1" == "/restore" set MSBuildTarget=Restore&&shift&& goto :ParseArguments
2222
if /I "%1" == "/no-node-reuse" set NodeReuse=false&&shift&& goto :ParseArguments
2323
if /I "%1" == "/no-multi-proc" set MultiProcessor=&&shift&& goto :ParseArguments
24-
set MSBuildAdditionalArguments=%1 %MSBuildAdditionalArguments%&&shift&& goto :ParseArguments
24+
set MSBuildAdditionalArguments=%MSBuildAdditionalArguments% %1&&shift&& goto :ParseArguments
2525
:DoneParsing
2626

2727
:: Detect if MSBuild is in the path
@@ -75,7 +75,9 @@ if "%VisualStudioVersion%" == "" (
7575
call "%DeveloperCommandPrompt%" || goto :BuildFailed
7676
)
7777

78-
msbuild /nologo /nodeReuse:%NodeReuse% /t:"%MSBuildTarget%" /p:Configuration="%BuildConfiguration%" %MSBuildAdditionalArguments%
78+
@echo on
79+
msbuild /nologo /nodeReuse:%NodeReuse% /t:"%MSBuildTarget%" /p:target="%MSBuildTarget%" /p:Configuration="%BuildConfiguration%" %MSBuildAdditionalArguments%
80+
@echo off
7981
if ERRORLEVEL 1 (
8082
echo.
8183
call :PrintColor Red "Build failed, for full log see msbuild.log."

build.proj

Lines changed: 25 additions & 35 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'">
@@ -19,6 +20,7 @@
1920
<CommonBuildProperties>WarningLevel=0;NoWarn=1591;Out=$(Out);Configuration=$(Configuration);RunCodeAnalysis=$(RunCodeAnalysis);PackageOutputPath=$(Out)</CommonBuildProperties>
2021
<DefaultImportance Condition=" '$(DefaultImportance)' == '' ">high</DefaultImportance>
2122
<PS>%WINDIR%\System32\WindowsPowerShell\v1.0\powershell.exe</PS>
23+
<GitInfoReportImportance>high</GitInfoReportImportance>
2224
</PropertyGroup>
2325

2426
<ItemGroup>
@@ -28,6 +30,13 @@
2830
<TestProject Include="src\Build\**\*Tests.csproj" />
2931
</ItemGroup>
3032

33+
<ItemGroup>
34+
<PackageReference Include="GitInfo" Version="2.0.0" />
35+
<PackageReference Include="xunit.runner.console" Version="2.3.0-beta4-build3742" />
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">
@@ -39,7 +48,15 @@
3948

4049
<Target Name="Rebuild" DependsOnTargets="Clean;Build" />
4150

42-
<Target Name="Build">
51+
<Target Name="Build" DependsOnTargets="GitInfoReport;GetPackageVersion">
52+
<!-- For now this is an informative version #, used to update CI -->
53+
<Message Text="Building version $(PackageVersion)" Importance="high" />
54+
<!-- Update AppVeyor build # to match the actual one being used -->
55+
<Exec Command="appveyor UpdateBuild -Version $(PackageVersion)"
56+
Condition=" '$(APPVEYOR)' == 'true' "
57+
ConsoleToMSBuild="true"
58+
ContinueOnError="WarnAndContinue" />
59+
4360
<Exec Command="rmdir $(Out) /S /Q" Condition=" Exists('$(Out)') " ContinueOnError="true" StandardOutputImportance="low" />
4461
<MakeDir Directories="$(Out)" Condition="!Exists('$(Out)')" />
4562
<Message Text="Build properties: $(CommonBuildProperties)." Importance="high" />
@@ -67,21 +84,20 @@
6784
<MakeDir Directories="$(Out)" Condition="!Exists('$(Out)')" />
6885

6986
<PropertyGroup>
70-
<XunitConsole>"$(PackagesPath)\xunit.runner.console\tools\xunit.console.exe"</XunitConsole>
87+
<XunitConsole>"$(XunitConsolePath)"</XunitConsole>
7188
<XunitOptions>$(XunitOptions) -html $(Out)\test.html -xml $(Out)\test.xml -parallel all -noshadow</XunitOptions>
7289
</PropertyGroup>
7390

7491
<Exec Command="$(XunitConsole) @(TestAssembly, ' ') $(XunitOptions)" ConsoleToMSBuild="true" />
7592
</Target>
7693

77-
<Target Name="Restore">
94+
<Target Name="AfterRestore" AfterTargets="Restore">
7895
<ItemGroup>
7996
<RestoreProject Include="src\Build\NuGet.Build.Packaging.Tests\Scenarios\given_a_library_with_non_nugetized_reference\b.sln" />
8097
<RestoreProject Include="src\Build\NuGet.Build.Packaging.Tests\Scenarios\given_a_multi_platform_solution\forms.sln" />
8198
<RestoreProject Include="src\Build\NuGet.Build.Packaging.Tests\Scenarios\given_a_library_with_json_dependencies\a.csproj" />
8299
<RestoreProject Include="src\Build\NuGet.Build.Packaging.Tests\Scenarios\given_a_packaging_project_with_netstandard\a.nuproj" />
83100
<RestoreProject Include="src\Build\NuGet.Build.Packaging.Tests\Scenarios\given_a_library_with_private_assets_reference\a.csproj" />
84-
85101
</ItemGroup>
86102

87103
<MSBuild Projects="@(Solution);@(TestProject);@(RestoreProject)" Targets="Restore" Properties="$(CommonBuildProperties)" />
@@ -123,46 +139,20 @@
123139
<Exec Command="start $(Out)\coverage\index.htm" />
124140
</Target>
125141

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)')"/>
136142
<Target Name="GitVersion">
137143
<PropertyGroup>
138144
<GitSemVerMajor>1</GitSemVerMajor>
139145
<GitSemVerMinor>0</GitSemVerMinor>
140146
<GitSemVerPatch>0</GitSemVerPatch>
141147
</PropertyGroup>
142148
</Target>
143-
<Import Project="$(GitInfoTargets)" Condition="Exists('$(GitInfoTargets)')"/>
144149
<Import Project="src\PackageVersion.targets" />
145150

146-
<Target Name="Configure" DependsOnTargets="DownloadNuGet;GetPackageVersion">
151+
<Target Name="Configure">
147152
<Message Importance="high" Text="*********************************************************************************************************************" />
148153
<Message Importance="high" Text="$([System.Environment]::CommandLine)" />
149154
<Message Importance="high" Text="*********************************************************************************************************************" />
150-
151-
<Exec Command='"$(NuGet)" Install "$(MSBuildThisFileDirectory)packages.config" -OutputDirectory "$(PackagesPath)" -ExcludeVersion -Verbosity quiet'
152-
StandardOutputImportance="low"
153-
Condition=" '$(PendingRestore)' == 'true' " />
154-
155-
<!-- Invoke GitVersion just like the project-level targets do -->
156-
<MSBuild Projects="$(GitInfoTargets)" Targets="GitVersion;GitInfoReport" Properties="GitInfoReportImportance=high">
157-
<Output TaskParameter="TargetOutputs" ItemName="GitInfo" />
158-
</MSBuild>
159-
160-
<!-- For now this is an informative version #, used to update CI -->
161-
<Message Text="Building version $(PackageVersion)" Importance="high" />
162-
163-
<!-- Update AppVeyor build # to match the actual one being used -->
164-
<Exec Command="appveyor UpdateBuild -Version $(PackageVersion)" Condition=" '$(APPVEYOR)' == 'true' "
165-
ConsoleToMSBuild="true"
166-
ContinueOnError="WarnAndContinue" />
167155
</Target>
168-
</Project>
156+
157+
<Import Project="corebuild\corebuild.targets" />
158+
</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>

src/PackageVersion.targets

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33

44
<PropertyGroup>
5-
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
5+
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
6+
<!-- We use branch and file version sources only -->
7+
<GitIgnoreTagVersion>true</GitIgnoreTagVersion>
68
<BuildDependsOn>
79
GetPackageVersion;
810
$(BuildDependsOn)
@@ -11,13 +13,19 @@
1113

1214
<Target Name="GetPackageVersion" BeforeTargets="ThisProjectInfo" DependsOnTargets="GitVersion" Returns="$(PackageVersion)">
1315
<PropertyGroup>
14-
<GitSemVerDashLabel Condition="'$(GitBranch)' == 'undefined'">-pr</GitSemVerDashLabel>
16+
<!-- PR builds are *always* prerelease -->
17+
<!-- TFS case: BUILD_REASON=PullRequest and BUILD_SOURCEBRANCH=refs/pull/[#]/merge -->
18+
<GitSemVerDashLabel Condition="'$(TF_BUILD)' == 'true' and '$(BUILD_REASON)' == 'PullRequest'">-pr$(BUILD_SOURCEBRANCH.Substring(10).TrimEnd('/merge'))</GitSemVerDashLabel>
1519
<GitSemVerDashLabel Condition="'$(APPVEYOR_PULL_REQUEST_NUMBER)' != ''">-pr$(APPVEYOR_PULL_REQUEST_NUMBER)</GitSemVerDashLabel>
16-
<PackageVersion>$(GitSemVerMajor).$(GitSemVerMinor).$(GitSemVerPatch)$(GitSemVerDashLabel)</PackageVersion>
20+
21+
<!-- Non-prerelease versions will use the package version determined by SemVer -->
22+
<PackageVersion Condition="'$(GitSemVerDashLabel)' == ''">$(GitSemVerMajor).$(GitSemVerMinor).$(GitSemVerPatch)</PackageVersion>
23+
<!-- Prerelease versions are fixed to the base version (this allows the stable versions to always be greater) and have the build number instead -->
24+
<PackageVersion Condition="'$(GitSemVerDashLabel)' != ''">$(GitSemVerMajor).$(GitSemVerMinor).$(GitBaseVersionPatch)$(GitSemVerDashLabel)-build$(GitCommits.PadLeft(4, '0'))</PackageVersion>
1725
</PropertyGroup>
1826
</Target>
1927

2028
<PropertyGroup>
2129
<PackageVersionImported>true</PackageVersionImported>
2230
</PropertyGroup>
23-
</Project>
31+
</Project>

0 commit comments

Comments
 (0)