0

在我的道具文件中,我将使用属性传递BUILD_VERSION给. 但是,我在对从 : 获取其值的属性执行操作时遇到错误。dotnet msbuild/p:BUILD_VERSION=1.2.3.4SubstringBuildVersionBUILD_VERSION

<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <IntermediateOutputPath>./obj/</IntermediateOutputPath>
    <BuildVersion>$(BUILD_VERSION)</BuildVersion>
    <InformationalVersion>$(BuildVersion)</InformationalVersion>
    <BuildMajorVersion>$([System.String]::Concat($(BuildVersion.Substring(0, $(BuildVersion.IndexOf('.')))), ".0.0.0"))</BuildMajorVersion>
    <AssemblyVersion>$(BuildMajorVersion)</AssemblyVersion>
    <AssemblyFileVersion>$(BuildMajorVersion)</AssemblyFileVersion>
  </PropertyGroup>

我得到的错误是:""".Substring(0,-1)" length should be inside the string

我通过在 中打印来检查它BUILD_VERSION是否存在Message

  <Target Name="SetBuildVersions" BeforeTargets="BeforeBuild">
    <Message Importance="High" Text="BUILD_VERSION=$(BUILD_VERSION)"/>
  </Target>

它打印BUILD_VERSION=1.2.3.4

如果我硬编码<BuildVersion>1.2.3.4</BuildVersion>而不是<BuildVersion>$(BUILD_VERSION)</BuildVersion>下面,它可以工作。

如果我Substring在 a 中使用代码,Target它可以工作:

  <Target Name="SetBuildVersions" BeforeTargets="BeforeBuild">
    <PropertyGroup>
      <InformationalVersion>$(BuildVersion)</InformationalVersion>
      <BuildMajorVersionOnly>$([System.String]::Concat($(BuildVersion.Substring(0, $(BuildVersion.IndexOf('.')))), ".0.0.0"))</BuildMajorVersionOnly>
      <AssemblyVersion>$(BuildMajorVersionOnly)</AssemblyVersion>
      <AssemblyFileVersion>$(BuildMajorVersionOnly)</AssemblyFileVersion>
    </PropertyGroup>
  </Target>

当作为属性参数传递给时,为什么我不能使用Substring内部法线?PropertyGroupBUILD_VERSIONmsbuild

4

0 回答 0