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

Commit

Permalink
Merge pull request #144 from kzu/vsts
Browse files Browse the repository at this point in the history
Auto-push for versioned branches, improve TFS support
  • Loading branch information
kzu authored Aug 23, 2017
2 parents 09d2c92 + 10216e1 commit 258ab17
Show file tree
Hide file tree
Showing 9 changed files with 112 additions and 44 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ temp
NuGet.exe
packages
project.lock.json
.nuget
*.nuget.props
*.nuget.targets

Expand Down
2 changes: 1 addition & 1 deletion GitInfo.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.0
0.2.0-dev
3 changes: 1 addition & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ deploy:
api_key:
secure: 7MS5+XWaFchMXFqzgneQCqo9U0DlxiPXe/KWWUnbCBDEizVn06EjdQZkWu1gbNOJ
on:
# we only deploy to public NuGet gallery when tagging the repo
appveyor_repo_tag: true
branch: /v\d+\.\d+\.\d+/

nuget:
project_feed: true
Expand Down
6 changes: 4 additions & 2 deletions build.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ if /I "%1" == "/test" set MSBuildTarget=Test&&shift&& goto :ParseArguments
if /I "%1" == "/restore" set MSBuildTarget=Restore&&shift&& goto :ParseArguments
if /I "%1" == "/no-node-reuse" set NodeReuse=false&&shift&& goto :ParseArguments
if /I "%1" == "/no-multi-proc" set MultiProcessor=&&shift&& goto :ParseArguments
set MSBuildAdditionalArguments=%1 %MSBuildAdditionalArguments%&&shift&& goto :ParseArguments
set MSBuildAdditionalArguments=%MSBuildAdditionalArguments% %1&&shift&& goto :ParseArguments
:DoneParsing

:: Detect if MSBuild is in the path
Expand Down Expand Up @@ -75,7 +75,9 @@ if "%VisualStudioVersion%" == "" (
call "%DeveloperCommandPrompt%" || goto :BuildFailed
)

msbuild /nologo /nodeReuse:%NodeReuse% /t:"%MSBuildTarget%" /p:Configuration="%BuildConfiguration%" %MSBuildAdditionalArguments%
@echo on
msbuild /nologo /nodeReuse:%NodeReuse% /t:"%MSBuildTarget%" /p:target="%MSBuildTarget%" /p:Configuration="%BuildConfiguration%" %MSBuildAdditionalArguments%
@echo off
if ERRORLEVEL 1 (
echo.
call :PrintColor Red "Build failed, for full log see msbuild.log."
Expand Down
60 changes: 25 additions & 35 deletions build.proj
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="All" InitialTargets="Configure" TreatAsLocalProperty="RootSuffix" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project DefaultTargets="All" InitialTargets="Configure" TreatAsLocalProperty="RootSuffix" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="corebuild\corebuild.props" />
<Import Project="build.props" />

<PropertyGroup Condition="'$(IsCIBuild)' != 'true'">
Expand All @@ -19,6 +20,7 @@
<CommonBuildProperties>WarningLevel=0;NoWarn=1591;Out=$(Out);Configuration=$(Configuration);RunCodeAnalysis=$(RunCodeAnalysis);PackageOutputPath=$(Out)</CommonBuildProperties>
<DefaultImportance Condition=" '$(DefaultImportance)' == '' ">high</DefaultImportance>
<PS>%WINDIR%\System32\WindowsPowerShell\v1.0\powershell.exe</PS>
<GitInfoReportImportance>high</GitInfoReportImportance>
</PropertyGroup>

<ItemGroup>
Expand All @@ -28,6 +30,13 @@
<TestProject Include="src\Build\**\*Tests.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="GitInfo" Version="2.0.0" />
<PackageReference Include="xunit.runner.console" Version="2.3.0-beta4-build3742" />
<PackageReference Include="OpenCover" Version="4.6.519" />
<PackageReference Include="ReportGenerator" Version="2.4.5" />
</ItemGroup>

<Target Name="All" DependsOnTargets="Build;Test;Package" />

<Target Name="Clean">
Expand All @@ -39,7 +48,15 @@

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

<Target Name="Build">
<Target Name="Build" DependsOnTargets="GitInfoReport;GetPackageVersion">
<!-- For now this is an informative version #, used to update CI -->
<Message Text="Building version $(PackageVersion)" Importance="high" />
<!-- Update AppVeyor build # to match the actual one being used -->
<Exec Command="appveyor UpdateBuild -Version $(PackageVersion)"
Condition=" '$(APPVEYOR)' == 'true' "
ConsoleToMSBuild="true"
ContinueOnError="WarnAndContinue" />

<Exec Command="rmdir $(Out) /S /Q" Condition=" Exists('$(Out)') " ContinueOnError="true" StandardOutputImportance="low" />
<MakeDir Directories="$(Out)" Condition="!Exists('$(Out)')" />
<Message Text="Build properties: $(CommonBuildProperties)." Importance="high" />
Expand Down Expand Up @@ -67,21 +84,20 @@
<MakeDir Directories="$(Out)" Condition="!Exists('$(Out)')" />

<PropertyGroup>
<XunitConsole>"$(PackagesPath)\xunit.runner.console\tools\xunit.console.exe"</XunitConsole>
<XunitConsole>"$(XunitConsolePath)"</XunitConsole>
<XunitOptions>$(XunitOptions) -html $(Out)\test.html -xml $(Out)\test.xml -parallel all -noshadow</XunitOptions>
</PropertyGroup>

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

<Target Name="Restore">
<Target Name="AfterRestore" AfterTargets="Restore">
<ItemGroup>
<RestoreProject Include="src\Build\NuGet.Build.Packaging.Tests\Scenarios\given_a_library_with_non_nugetized_reference\b.sln" />
<RestoreProject Include="src\Build\NuGet.Build.Packaging.Tests\Scenarios\given_a_multi_platform_solution\forms.sln" />
<RestoreProject Include="src\Build\NuGet.Build.Packaging.Tests\Scenarios\given_a_library_with_json_dependencies\a.csproj" />
<RestoreProject Include="src\Build\NuGet.Build.Packaging.Tests\Scenarios\given_a_packaging_project_with_netstandard\a.nuproj" />
<RestoreProject Include="src\Build\NuGet.Build.Packaging.Tests\Scenarios\given_a_library_with_private_assets_reference\a.csproj" />

</ItemGroup>

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

<!-- Configure and restore initial targets and packages -->
<Import Project="src\NuGet.Restore.targets" />
<PropertyGroup>
<GitInfoTargets>$(PackagesPath)\GitInfo\build\GitInfo.targets</GitInfoTargets>
<XunitConsole>$(PackagesPath)\xunit.runner.console\tools\xunit.console.x86.exe</XunitConsole>
<XunitBuildDir>$([System.IO.Path]::Combine('$(MSBuildThisFileDirectory)', '.nuget', 'packages', 'xunit.runner.msbuild', 'build'))</XunitBuildDir>
<XunitProps>$([System.IO.Path]::Combine($(XunitBuildDir), 'xunit.runner.msbuild.props'))</XunitProps>
<PendingRestore Condition=" !Exists('$(GitInfoTargets)') Or !Exists('$(XunitConsole)') Or !Exists('$(XunitProps)') ">true</PendingRestore>
</PropertyGroup>
<Import Project="$(XunitProps)" Condition="Exists('$(XunitProps)')"/>
<Target Name="GitVersion">
<PropertyGroup>
<GitSemVerMajor>1</GitSemVerMajor>
<GitSemVerMinor>0</GitSemVerMinor>
<GitSemVerPatch>0</GitSemVerPatch>
</PropertyGroup>
</Target>
<Import Project="$(GitInfoTargets)" Condition="Exists('$(GitInfoTargets)')"/>
<Import Project="src\PackageVersion.targets" />

<Target Name="Configure" DependsOnTargets="DownloadNuGet;GetPackageVersion">
<Target Name="Configure">
<Message Importance="high" Text="*********************************************************************************************************************" />
<Message Importance="high" Text="$([System.Environment]::CommandLine)" />
<Message Importance="high" Text="*********************************************************************************************************************" />

<Exec Command='"$(NuGet)" Install "$(MSBuildThisFileDirectory)packages.config" -OutputDirectory "$(PackagesPath)" -ExcludeVersion -Verbosity quiet'
StandardOutputImportance="low"
Condition=" '$(PendingRestore)' == 'true' " />

<!-- Invoke GitVersion just like the project-level targets do -->
<MSBuild Projects="$(GitInfoTargets)" Targets="GitVersion;GitInfoReport" Properties="GitInfoReportImportance=high">
<Output TaskParameter="TargetOutputs" ItemName="GitInfo" />
</MSBuild>

<!-- For now this is an informative version #, used to update CI -->
<Message Text="Building version $(PackageVersion)" Importance="high" />

<!-- Update AppVeyor build # to match the actual one being used -->
<Exec Command="appveyor UpdateBuild -Version $(PackageVersion)" Condition=" '$(APPVEYOR)' == 'true' "
ConsoleToMSBuild="true"
ContinueOnError="WarnAndContinue" />
</Target>
</Project>

<Import Project="corebuild\corebuild.targets" />
</Project>
16 changes: 16 additions & 0 deletions corebuild/corebuild.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<!-- Instruct NuGet to perform a NETCore-like restore -->
<TargetFramework>netcore50</TargetFramework>
<!-- Instruct NuGet that we use PackageReference, rather than project.json -->
<RestoreProjectStyle>PackageReference</RestoreProjectStyle>
<!-- Specify a well-known usually ignored directory for the generated targets -->
<RestoreOutputPath>$(MSBuildThisFileDirectory).nuget</RestoreOutputPath>
<ETag>9f31d2c2a2dcddd79bfc28ddb5217663b761a17c</ETag>
<CoreBuildPropsImported>true</CoreBuildPropsImported>
</PropertyGroup>

<!-- NuGet generated targets -->
<Import Project="$(RestoreOutputPath)\$(MSBuildProjectFile).nuget.g.props" Condition="Exists('$(RestoreOutputPath)\$(MSBuildProjectFile).nuget.g.props')" />
</Project>
34 changes: 34 additions & 0 deletions corebuild/corebuild.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- Import NuGet.targets for Restore -->
<PropertyGroup>
<NuGetRestoreTargets Condition="'$(NuGetRestoreTargets)'==''">$(VsInstallRoot)\Common7\IDE\CommonExtensions\Microsoft\NuGet\NuGet.targets</NuGetRestoreTargets>
</PropertyGroup>
<Import Condition="Exists('$(NuGetRestoreTargets)')" Project="$(NuGetRestoreTargets)" />
<Import Condition="'$(CoreBuildPropsImported)' == ''" Project="corebuild.props" />

<Import Project="$(RestoreOutputPath)\$(MSBuildProjectFile).nuget.g.targets" Condition="Exists('$(RestoreOutputPath)\$(MSBuildProjectFile).nuget.g.targets')" />

<!-- Unfortunately, NuGet restore depends on this target for its _GenerateRestoreProjectReferencePaths target -->
<Target Name="_SplitProjectReferencesByFileExistence" />

<Target Name="GetVsInstallRoot" Returns="$(VsInstallRoot)">
<Message Importance="high" Text="$(VsInstallRoot)" />
</Target>

<ItemGroup>
<PackageReference Include="CoreBuild.Updater" Version="*">
<PrivateAssets>All</PrivateAssets>
</PackageReference>
<PackageReference Include="MSBuilder.XmlPoke" Version="*">
<PrivateAssets>All</PrivateAssets>
</PackageReference>
</ItemGroup>

<PropertyGroup>
<ETag>cdac7d6eaa07b64767e32bcb207a7dbdce1caf07</ETag>
</PropertyGroup>

<!-- If we're being imported from another project, import the update-all version of Update -->
<Import Project="update.targets" Condition="'$(MSBuildProjectFullPath)' != '(MSBuildThisFileFullPath)' And '$(IsUpdating)' != 'true'" />
</Project>
18 changes: 18 additions & 0 deletions corebuild/update.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<UpdateBaseUrl>https://raw.githubusercontent.com/kzu/corebuild/master/src/corebuild</UpdateBaseUrl>
</PropertyGroup>
<ItemGroup>
<_Updatable Include="$(MSBuildThisFileDirectory)corebuild.props" />
<_Updatable Include="$(MSBuildThisFileDirectory)corebuild.targets" />
</ItemGroup>

<Target Name="Update" Returns="@(_Updated)">
<MSBuild Projects="$(MSBuildProjectFullPath)"
Targets="Update"
Properties="UpdateTarget=%(_Updatable.FullPath);UpdateUrl=$(UpdateBaseUrl)/%(_Updatable.Filename)%(_Updatable.Extension);IsUpdating=true">
<Output TaskParameter="TargetOutputs" ItemName="_Updated" />
</MSBuild>
</Target>
</Project>
16 changes: 12 additions & 4 deletions src/PackageVersion.targets
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<PropertyGroup>
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
<!-- We use branch and file version sources only -->
<GitIgnoreTagVersion>true</GitIgnoreTagVersion>
<BuildDependsOn>
GetPackageVersion;
$(BuildDependsOn)
Expand All @@ -11,13 +13,19 @@

<Target Name="GetPackageVersion" BeforeTargets="ThisProjectInfo" DependsOnTargets="GitVersion" Returns="$(PackageVersion)">
<PropertyGroup>
<GitSemVerDashLabel Condition="'$(GitBranch)' == 'undefined'">-pr</GitSemVerDashLabel>
<!-- PR builds are *always* prerelease -->
<!-- TFS case: BUILD_REASON=PullRequest and BUILD_SOURCEBRANCH=refs/pull/[#]/merge -->
<GitSemVerDashLabel Condition="'$(TF_BUILD)' == 'true' and '$(BUILD_REASON)' == 'PullRequest'">-pr$(BUILD_SOURCEBRANCH.Substring(10).TrimEnd('/merge'))</GitSemVerDashLabel>
<GitSemVerDashLabel Condition="'$(APPVEYOR_PULL_REQUEST_NUMBER)' != ''">-pr$(APPVEYOR_PULL_REQUEST_NUMBER)</GitSemVerDashLabel>
<PackageVersion>$(GitSemVerMajor).$(GitSemVerMinor).$(GitSemVerPatch)$(GitSemVerDashLabel)</PackageVersion>

<!-- Non-prerelease versions will use the package version determined by SemVer -->
<PackageVersion Condition="'$(GitSemVerDashLabel)' == ''">$(GitSemVerMajor).$(GitSemVerMinor).$(GitSemVerPatch)</PackageVersion>
<!-- Prerelease versions are fixed to the base version (this allows the stable versions to always be greater) and have the build number instead -->
<PackageVersion Condition="'$(GitSemVerDashLabel)' != ''">$(GitSemVerMajor).$(GitSemVerMinor).$(GitBaseVersionPatch)$(GitSemVerDashLabel)-build$(GitCommits.PadLeft(4, '0'))</PackageVersion>
</PropertyGroup>
</Target>

<PropertyGroup>
<PackageVersionImported>true</PackageVersionImported>
</PropertyGroup>
</Project>
</Project>

0 comments on commit 258ab17

Please sign in to comment.