Valentine
Valentine

Reputation: 516

Patch version of ASP Core (preview 4) with AppVeyor

How to patch Asp.Net Core project (csproj) in order to build versioned binaries with AppVeyor? Is there a way to apply versioning separately for AssemblyVersion and FileVersion?

AppVeyor has predefined step to patch AssemblyInfo.cs file, but it isn't included into project and functionality of AssemblyInfo moved to csproj file, therefore it's not clear how to deal with versioning.

Appreciate you help!

Upvotes: 1

Views: 164

Answers (1)

Feodor Fitsner
Feodor Fitsner

Reputation: 2354

As .NET Core .csproj is a regular XML you can use PowerShell script to update the version information in it. For example, you might have the following MyProject\MyProject.csproj:

<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp1.0</TargetFramework>
    <Version>1.2.3.4</Version>
  </PropertyGroup>
  <ItemGroup>
    <Compile Include="**\*.cs" />
    <EmbeddedResource Include="**\*.resx" />
  </ItemGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.NETCore.App" Version="1.0.1" />
  </ItemGroup>
</Project>

Then on AppVeyor the script patching <Version> would be the following:

$xmlPath = "$env:appveyor_build_folder\MyProject\MyProject.csproj"
$xml = [xml](get-content $xmlPath)
$propertyGroup = $xml.Project.PropertyGroup | Where { $_.Version}
$propertyGroup.Version = $env:appveyor_build_version
$xml.Save($xmlPath)

Upvotes: 4

Related Questions