使用AppVeyor修补ASP Core版本(预览版4)

时间:2017-02-24 11:28:00

标签: asp.net .net .net-core appveyor

如何修补Asp.Net Core项目(csproj)以便使用AppVeyor构建版本化的二进制文件? 有没有办法单独为AssemblyVersion和FileVersion应用版本控制?

AppVeyor已经预定义了修补AssemblyInfo.cs文件的步骤,但它未包含在项目中,而且AssemblyInfo的功能已移至csproj文件,因此不清楚如何处理版本控制。

感谢您的帮助!

1 个答案:

答案 0 :(得分:4)

由于.NET Core .csproj是常规XML,您可以使用PowerShell脚本更新其中的版本信息。例如,您可能拥有以下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>

然后在AppVeyor上,脚本修补<Version>将如下:

$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)
相关问题