Skip to content

Support for Visual Studio Online Build vNext - VSO Build Step #562

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ ForSample/
*NugetTaskBuild*
*NugetRefBuild*
*NugetExeBuild*
*GitVersionVsoTaskBuild*
*GemBuild*

# Visual Studio profiler
Expand Down
26 changes: 26 additions & 0 deletions docs/more-info/build-server-setup/tfs-build-vnext.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Visual Studio Online (Build vNext) Setup
## Basic Usage
In [Visual Studio Online](https://www.visualstudio.com/) build vNext (the web based build system) you can add a build step as follows:

* **Build Step:** Command Line
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why command line when this PR is about a custom build step?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's old and needs to change. That refers to using GitVersion.exe as a standalone. That won't get past the detached head issues that the VSO build step does. I'll update the docs.

* Might need to fully qualify the path.
* Tip: Use a script and/or another command step to call `NuGet Install GitVersion.CommandLine` first so you don't have to check in the exe.
* **Tool:** `GitVersion.exe`
* **Arguments:** `/output buildserver /updateassemblyinfo true`

Then in your build parameters simply [add a placeholder](#nuget-in-teamcity) of the GitVersion variables you would like to use.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like copy/past from TeamCity documentation and not accurate for this PR


GitVersion writes build parameters into VSO, so they will automatically be passed to your build scripts to use.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this works at the moment


## GitVersion Build Step for VSO
Visual Studio Online has support for custom build steps. This is planned but TBD. For now, the command line does work.


## Running inside TeamCity
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like copy/past from TeamCity documentation and not accurate for this PR

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was and it did work originally....will update! That's on the to do notes at the top :)

* We output the individual values of the GitVersion version as the build parameter: `GitVersion.*` (Eg: `GitVersion.Major`) if you need access to them in your build script

### NuGet in VSO
* Add dummy parameter to the project called `GitVersion.NuGetVersion`.
* Then setup you nuget pack build set the "version" to `%GitVersion.NuGetVersion%`


26 changes: 26 additions & 0 deletions src/GitVersionCore.Tests/BuildServers/VsoAgentTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using GitVersion;
using NUnit.Framework;

[TestFixture]
public class VsoAgentTests
{
[Test]
public void Develop_branch()
{
var versionBuilder = new VsoAgent();
var vsVersion = versionBuilder.GenerateSetVersionMessage("0.0.0-Unstable4");
// Assert.AreEqual("##vso[task.setvariable variable=GitBuildNumber;]0.0.0-Unstable4", vsVersion);

Assert.Null(vsVersion);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor thing, but using Shouldly will give much better error messages. vsVersion.ShouldBe(null)

I think I am going to move to xUnit so there is not the option for using the inbuilt assertions, not going to block PR though, I will cleanup later

}

[Test]
public void EscapeValues()
{
var versionBuilder = new VsoAgent();
var vsVersion = versionBuilder.GenerateSetParameterMessage("Foo", "0.8.0-unstable568 Branch:'develop' Sha:'ee69bff1087ebc95c6b43aa2124bd58f5722e0cb'");
Assert.AreEqual("##vso[task.setvariable variable=GitVersion.Foo;]0.8.0-unstable568 Branch:'develop' Sha:'ee69bff1087ebc95c6b43aa2124bd58f5722e0cb'", vsVersion[0]);

}

}
22 changes: 21 additions & 1 deletion src/GitVersionCore.Tests/GitVersionCore.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,26 @@
<HintPath>..\packages\Mono.Cecil.0.9.6.1\lib\net45\Mono.Cecil.Rocks.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="nunit.core, Version=2.6.4.14350, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<HintPath>..\packages\NUnitTestAdapter.2.0.0\lib\nunit.core.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="nunit.core.interfaces, Version=2.6.4.14350, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<HintPath>..\packages\NUnitTestAdapter.2.0.0\lib\nunit.core.interfaces.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="nunit.framework, Version=2.6.4.14350, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\NUnit.2.6.4\lib\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="nunit.util, Version=2.6.4.14350, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<HintPath>..\packages\NUnitTestAdapter.2.0.0\lib\nunit.util.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="NUnit.VisualStudio.TestAdapter, Version=2.0.0.0, Culture=neutral, PublicKeyToken=4cb40d35494691ac, processorArchitecture=MSIL">
<HintPath>..\packages\NUnitTestAdapter.2.0.0\lib\NUnit.VisualStudio.TestAdapter.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Shouldly, Version=2.5.0.0, Culture=neutral, PublicKeyToken=6042cbcb05cbc941, processorArchitecture=MSIL">
<HintPath>..\packages\Shouldly.2.5.0\lib\net40\Shouldly.dll</HintPath>
<Private>True</Private>
Expand All @@ -98,6 +114,7 @@
<Compile Include="BuildServers\BuildServerBaseTests.cs" />
<Compile Include="BuildServers\ContinuaCiTests.cs" />
<Compile Include="BuildServers\MyGetTests.cs" />
<Compile Include="BuildServers\VsoAgentTests.cs" />
<Compile Include="BuildServers\TeamCityTests.cs" />
<Compile Include="Fixtures\CommitCountingRepoFixture.cs" />
<Compile Include="ConfigProviderTests.cs" />
Expand Down Expand Up @@ -160,6 +177,7 @@
<Compile Include="VersionCalculation\TestMetaDataCalculator.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
Expand All @@ -172,7 +190,9 @@
<Content Include="FodyWeavers.xml" />
<Content Include="JsonVersionBuilderTests.Json.approved.txt" />
</ItemGroup>
<ItemGroup />
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>
Expand Down
11 changes: 11 additions & 0 deletions src/GitVersionCore.Tests/app.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Mono.Cecil" publicKeyToken="0738eb9f132ed756" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-0.9.6.0" newVersion="0.9.6.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
1 change: 1 addition & 0 deletions src/GitVersionCore.Tests/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<package id="LibGit2Sharp" version="0.20.1.0" targetFramework="net45" />
<package id="Mono.Cecil" version="0.9.6.1" targetFramework="net45" />
<package id="NUnit" version="2.6.4" targetFramework="net45" />
<package id="NUnitTestAdapter" version="2.0.0" targetFramework="net45" />
<package id="Shouldly" version="2.5.0" targetFramework="net45" />
<package id="TestStack.ConventionTests" version="2.2.1" targetFramework="net45" />
<package id="YamlDotNet" version="3.5.1" targetFramework="net45" />
Expand Down
3 changes: 2 additions & 1 deletion src/GitVersionCore/BuildServers/BuildServerList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ public static class BuildServerList
new ContinuaCi(),
new TeamCity(),
new AppVeyor(),
new MyGet()
new MyGet(),
new VsoAgent()
};

public static IEnumerable<IBuildServer> GetApplicableBuildServers()
Expand Down
26 changes: 26 additions & 0 deletions src/GitVersionCore/BuildServers/VsoAgent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
namespace GitVersion
{
using System;

public class VsoAgent : BuildServerBase
{
public override bool CanApplyToCurrentContext()
{
return !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("TF_BUILD"));
}

public override string[] GenerateSetParameterMessage(string name, string value)
{
return new[]
{
string.Format("##vso[task.setvariable variable=GitVersion.{0};]{1}", name, value)
};
}

public override string GenerateSetVersionMessage(string versionToUseForBuildNumber)
{
// Note: the VSO agent does not yet support updating the build display number from a variable
return null;
}
}
}
1 change: 1 addition & 0 deletions src/GitVersionCore/GitVersionCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
<Compile Include="BuildServers\IBuildServer.cs" />
<Compile Include="BuildServers\MyGet.cs" />
<Compile Include="BuildServers\TeamCity.cs" />
<Compile Include="BuildServers\VsoAgent.cs" />
<Compile Include="Configuration\BranchConfig.cs" />
<Compile Include="Configuration\Config.cs" />
<Compile Include="Configuration\ConsoleAdapter.cs" />
Expand Down
17 changes: 17 additions & 0 deletions src/GitVersionExe.Tests/GitVersionExe.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,26 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\NSubstitute.1.8.1.0\lib\net45\NSubstitute.dll</HintPath>
</Reference>
<Reference Include="nunit.core, Version=2.6.4.14350, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<HintPath>..\packages\NUnitTestAdapter.2.0.0\lib\nunit.core.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="nunit.core.interfaces, Version=2.6.4.14350, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<HintPath>..\packages\NUnitTestAdapter.2.0.0\lib\nunit.core.interfaces.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="nunit.framework, Version=2.6.4.14350, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\NUnit.2.6.4\lib\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="nunit.util, Version=2.6.4.14350, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<HintPath>..\packages\NUnitTestAdapter.2.0.0\lib\nunit.util.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="NUnit.VisualStudio.TestAdapter, Version=2.0.0.0, Culture=neutral, PublicKeyToken=4cb40d35494691ac, processorArchitecture=MSIL">
<HintPath>..\packages\NUnitTestAdapter.2.0.0\lib\NUnit.VisualStudio.TestAdapter.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Shouldly, Version=2.5.0.0, Culture=neutral, PublicKeyToken=6042cbcb05cbc941, processorArchitecture=MSIL">
<HintPath>..\packages\Shouldly.2.5.0\lib\net40\Shouldly.dll</HintPath>
<Private>True</Private>
Expand Down Expand Up @@ -82,6 +98,7 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="packages.config">
<SubType>Designer</SubType>
</None>
Expand Down
11 changes: 11 additions & 0 deletions src/GitVersionExe.Tests/app.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Mono.Cecil" publicKeyToken="0738eb9f132ed756" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-0.9.6.0" newVersion="0.9.6.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
1 change: 1 addition & 0 deletions src/GitVersionExe.Tests/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
<package id="LibGit2Sharp" version="0.20.1.0" targetFramework="net45" />
<package id="NSubstitute" version="1.8.1.0" targetFramework="net45" />
<package id="NUnit" version="2.6.4" targetFramework="net45" />
<package id="NUnitTestAdapter" version="2.0.0" targetFramework="net45" />
<package id="Shouldly" version="2.5.0" targetFramework="net45" />
</packages>
12 changes: 6 additions & 6 deletions src/GitVersionExe/ArgumentParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,11 @@ public static Arguments ParseArguments(List<string> commandLineArguments)

if (IsSwitch("updateAssemblyInfo", name))
{
if (new[] { "1", "true" }.Contains(value))
if (new[] { "1", "true" }.Contains(value, StringComparer.OrdinalIgnoreCase))
{
arguments.UpdateAssemblyInfo = true;
}
else if (new[] { "0", "false" }.Contains(value))
else if (new[] { "0", "false" }.Contains(value, StringComparer.OrdinalIgnoreCase))
{
arguments.UpdateAssemblyInfo = false;
}
Expand Down Expand Up @@ -200,11 +200,11 @@ public static Arguments ParseArguments(List<string> commandLineArguments)

if (IsSwitch("showConfig", name))
{
if (new[] { "1", "true" }.Contains(value))
if (new[] { "1", "true" }.Contains(value, StringComparer.OrdinalIgnoreCase))
{
arguments.ShowConfig = true;
}
else if (new[] { "0", "false" }.Contains(value))
else if (new[] { "0", "false" }.Contains(value, StringComparer.OrdinalIgnoreCase))
{
arguments.UpdateAssemblyInfo = false;
}
Expand Down Expand Up @@ -289,12 +289,12 @@ static bool IsSwitch(string switchName, string value)
value = value.Remove(0, 1);
}

return (string.Equals(switchName, value, StringComparison.InvariantCultureIgnoreCase));
return (string.Equals(switchName, value, StringComparison.OrdinalIgnoreCase));
}

static bool IsInit(string singleArgument)
{
return singleArgument.Equals("init", StringComparison.InvariantCultureIgnoreCase);
return singleArgument.Equals("init", StringComparison.OrdinalIgnoreCase);
}

static bool IsHelp(string singleArgument)
Expand Down
11 changes: 10 additions & 1 deletion src/GitVersionExe/GitVersionExe.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="Clean">
<ItemGroup>
<ExeFilesToDelete Include="$(BuildDir)NuGetExeBuild\**\*.*;$(BuildDir)NuGetCommandLineBuild\**\*.*" />
<ExeFilesToDelete Include="$(BuildDir)NuGetExeBuild\**\*.*;$(BuildDir)NuGetCommandLineBuild\**\*.*;$(BuildDir)GitVersionVsoTaskBuild\**\*.*" />
</ItemGroup>
<Delete Files="@(ExeFilesToDelete)" />
</Target>
Expand Down Expand Up @@ -146,6 +146,15 @@
<Copy SourceFiles="$(OutputPath)\GitVersion.exe" DestinationFolder="$(BuildDir)NuGetCommandLineBuild\tools" />
<Copy SourceFiles="$(ProjectDir)NugetAssets\GitVersion.CommandLine.nuspec" DestinationFolder="$(BuildDir)NuGetCommandLineBuild" />
<PepitaPackage.CreatePackageTask NuGetBuildDirectory="$(BuildDir)NuGetCommandLineBuild" MetadataAssembly="$(OutputPath)GitVersion.exe" Version="$(GitVersion_NuGetVersion)" />

<!-- VsoBuildTask -->
<MakeDir Directories="$(BuildDir)GitVersionVsoTaskBuild" />
<Copy SourceFiles="$(OutputPath)\GitVersion.pdb" DestinationFolder="$(BuildDir)GitVersionVsoTaskBuild" />
<Copy SourceFiles="$(OutputPath)\GitVersion.exe" DestinationFolder="$(BuildDir)GitVersionVsoTaskBuild" />
<Copy SourceFiles="$(ProjectDir)..\GitVersionVsoTask\icon.png" DestinationFolder="$(BuildDir)GitVersionVsoTaskBuild" />
<Copy SourceFiles="$(ProjectDir)..\GitVersionVsoTask\Run-GitVersion.ps1" DestinationFolder="$(BuildDir)GitVersionVsoTaskBuild" />
<Copy SourceFiles="$(ProjectDir)..\GitVersionVsoTask\task.json" DestinationFolder="$(BuildDir)GitVersionVsoTaskBuild" />

<!-- Gem -->
<Copy SourceFiles="$(OutputPath)\GitVersion.pdb" DestinationFolder="$(BuildDir)GemBuild\bin" />
<Copy SourceFiles="$(OutputPath)\GitVersion.exe" DestinationFolder="$(BuildDir)GemBuild\bin" />
Expand Down
16 changes: 16 additions & 0 deletions src/GitVersionTask.Tests/GitVersionTask.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,26 @@
<Reference Include="Microsoft.Web.XmlTransform">
<HintPath>..\packages\Microsoft.Web.Xdt.1.0.0\lib\net40\Microsoft.Web.XmlTransform.dll</HintPath>
</Reference>
<Reference Include="nunit.core, Version=2.6.4.14350, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<HintPath>..\packages\NUnitTestAdapter.2.0.0\lib\nunit.core.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="nunit.core.interfaces, Version=2.6.4.14350, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<HintPath>..\packages\NUnitTestAdapter.2.0.0\lib\nunit.core.interfaces.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="nunit.framework, Version=2.6.4.14350, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\NUnit.2.6.4\lib\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="nunit.util, Version=2.6.4.14350, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<HintPath>..\packages\NUnitTestAdapter.2.0.0\lib\nunit.util.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="NUnit.VisualStudio.TestAdapter, Version=2.0.0.0, Culture=neutral, PublicKeyToken=4cb40d35494691ac, processorArchitecture=MSIL">
<HintPath>..\packages\NUnitTestAdapter.2.0.0\lib\NUnit.VisualStudio.TestAdapter.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="ObjectApproval, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\ObjectApproval.1.0.0\Lib\NET40\ObjectApproval.dll</HintPath>
Expand Down
4 changes: 4 additions & 0 deletions src/GitVersionTask.Tests/app.config
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
<assemblyIdentity name="nunit.framework" publicKeyToken="96d09a1eb7f44a77" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.6.4.14350" newVersion="2.6.4.14350" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Mono.Cecil" publicKeyToken="0738eb9f132ed756" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-0.9.6.0" newVersion="0.9.6.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
3 changes: 2 additions & 1 deletion src/GitVersionTask.Tests/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
<package id="LibGit2Sharp" version="0.20.1.0" targetFramework="net45" />
<package id="Microsoft.CodeAnalysis.Common" version="1.0.0.0-beta2" targetFramework="net45" />
<package id="Microsoft.CodeAnalysis.CSharp" version="1.0.0.0-beta2" targetFramework="net45" />
<package id="Microsoft.Web.Xdt" version="1.0.0" targetFramework="net40" />
<package id="Microsoft.Web.Xdt" version="1.0.0" targetFramework="net4" />
<package id="ModuleInit.Fody" version="1.5.6.0" targetFramework="net45" developmentDependency="true" />
<package id="NUnit" version="2.6.4" targetFramework="net45" />
<package id="NUnitTestAdapter" version="2.0.0" targetFramework="net45" />
<package id="ObjectApproval" version="1.0.0" targetFramework="net45" />
<package id="Shouldly" version="2.5.0" targetFramework="net45" />
<package id="System.Collections.Immutable" version="1.1.32-beta" targetFramework="net45" />
Expand Down
Loading