How to Auto Increment Assembly or Assembly File Ve

2019-02-11 01:40发布

问题:

Constraints are: Using Visual Studio 2017. Needs to ultimately be called from a powershell script calling MSBuild.

Not sure its relevant, but needs to be able to build the following:

  • asp.net 461
  • asp.net-core 1.1 and 2.0 assemblies

Unsuccessful attempts so far:

  • How to have an auto incrementing version number (Visual Studio)? <- This works when building from VS only.
  • Code Generation in a Build Process -Described as Microsoft's latest document on using "TextTemplating" with MSBuild. States need to copy certain DLLs to build server.. Files are not located where specified in doc, and dont know where to copy them, I have found all files. Additionally modified .csproj's import Microsoft.TextTemplating.targets path to correct location but when running MSBuild I get. "error MSB4018: The "TransformTemplates" task failed unexpectedly."
  • This SO Answer - MSBuild support for T4 templates in Visual Studio 2017 RTM <- Give same MSBuild Runtime error as above.

Example attempt of "Code Generation in a Build Process" That works on build from VS but not MSBuild:

placed in root of project - handleVersioning.tt:

<#@ template language="C#" #>

using System.Reflection;

[assembly: AssemblyVersion("1.0.0.*")]
[assembly: AssemblyFileVersion("<#= this.Year #>.<#= this.Month #>.<#= this.Day #>.<#= this.Minute #>")]
<#+
    int Year = DateTime.UtcNow.Year;
    int Month = DateTime.UtcNow.Month;
    int Day = DateTime.UtcNow.Day;
    int Minute = unchecked((int)DateTime.UtcNow.TimeOfDay.TotalMinutes);
#>

.csproj:

<Import Project="...hardcoded...\Microsoft.CSharp.targets" />
<!-- This is the important line: -->  
<Import Project="...hardcoded...\TextTemplating\Microsoft.TextTemplating.targets" />

<PropertyGroup>  
    <TransformOnBuild>true</TransformOnBuild>  
    <OverwriteReadOnlyOutputFiles>true</OverwriteReadOnlyOutputFiles>
    <TransformOutOfDateOnly>false</TransformOutOfDateOnly>
</PropertyGroup> 

Called like so: msbuild myProject.csproj /t:TransformAll

标签: msbuild t4