蛋糕获取版本 - 重复的"程序集信息版本"属性



由于某种原因,cakebuild.net任务执行过程中出现错误。

错误的根本原因是UpdateAssemblyInfo = true属性。看起来属性重复发生了。

但我不清楚为什么会发生这种事。你能透露的这种行为吗

先决条件:

  • 网络4.7.2

  • 不是.csproj 中的AssemblyInformationalVersion属性

  • 不是Properties \AssemblyInfo 中的AssemblyInformation Version属性

    var gitVersion = GitVersion(new GitVersionSettings
    {
    OutputType = GitVersionOutput.Json,
    NoFetch = false,
    UpdateAssemblyInfo = true
    });
    

错误:

Properties \AssemblyInfo.cs(41,12(:错误CS0579:重复的"AssemblyInformation Version"属性

对于SDK风格的项目,将始终生成AssemblyInfo(除非设置了<GenerateAssemblyInfo>false</GenerateAssemblyInfo>(。无论是否显式设置<AssemblyInformationalVersion>,生成的AssemblyInfo都将包含一些版本信息。

所以:在GitVersion中设置UpdateAssemblyInfo=true会创建一个AssemblyInfo,而您的csproj也会创建一。因此,出现了错误。

你可以做的是:获取版本并相应地设置构建属性,这样生成的AssemblyInfo就包含了你想要的信息

Task("Build")
.Does(() => {
// get version
var gitVersion = GitVersion();
var version = gitVersion.SemVer; // or something other...
Information($"Building version: {version}");
// add version to settings
var settings = new DotNetBuildSettings();
settings.MSBuildSettings = new DotNetCoreMSBuildSettings();
settings.MSBuildSettings.Properties.Add("AssemblyVersion", new[] { version });
settings.MSBuildSettings.Properties.Add("AssemblyFileVersion", new[] { version });
settings.MSBuildSettings.Properties.Add("AssemblyInformationalVersion", new [] { version });
settings.MSBuildSettings.Properties.Add("Version", new [] { version });
// build
DotNetBuild("./console/console.csproj", settings);
});

最新更新