当属性作为参数传递给msbuild

时间:2018-05-31 09:11:56

标签: c# msbuild vsprops

在我的道具档案中,我使用[{1}}属性将BUILD_VERSION传递给dotnet msbuild。但是,我对属性/p:BUILD_VERSION=1.2.3.4执行Substring操作时遇到错误,该操作的值来自:BuildVersion

BUILD_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内使用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>

为了SubstringPropertyGroup作为属性参数传递给BUILD_VERSION,为什么我不能在msbuild内使用 $(document).ready(function(){ var dataset; var data; var date; var temp1 = []; var temp2 = []; var url = "https://raw.githubusercontent.com/FreeCodeCamp/ProjectReferenceData/master/GDP-data.json"; d3.json(url, function(json) { dataset = json.data; for (var j = 0; j < dataset.length; j++) { temp1[j] = dataset[j][1] } data = temp1; for (var j = 0; j < dataset.length; j++) { temp2[j] = dataset[j][0] } date = temp2; minDate = new Date(date[0]); maxDate = new Date(date[date.length - 1]); var svgWidth = 1000; var svgHeight = 450; var barWidth = (svgWidth/data.length); var svg = d3.select("svg") .attr("width", svgWidth) .attr("height", svgHeight); var xScale = d3.scaleTime() .domain([minDate, maxDate]) .range([0, svgWidth]); var yScale = d3.scaleLinear() .domain([0, d3.max(data)]) .range([svgHeight, 0]); var x_axis = d3.axisBottom() .scale(xScale); var y_axis = d3.axisRight() .scale(yScale); var xAxisTranslate = svgHeight - 20; svg.append("g") .attr("transform", "translate(0 " + xAxisTranslate +")") .call(x_axis); svg.append("g") .attr("transform", "translate(0, -20)") .call(y_axis); var barChart = svg.selectAll("rect") .data(data) .enter() .append("rect") .attr("y", function(d) { return yScale(d); }) .attr("height", function(d) { return svgHeight - yScale(d); }) .attr("width", barWidth) .attr("transform", function (d, i) { var translate = [barWidth * i, - 20]; return "translate("+ translate +")"; }); }); });

0 个答案:

没有答案