Determine if MSBuild CoreCompile will run and call custom target

后端 未结 4 1975
旧巷少年郎
旧巷少年郎 2020-12-08 23:55

This seems like an obvious thing to want to do but I have pulled most of my hair out trying to find any examples on the web or do it myself.

I have a c# solution wit

4条回答
  •  误落风尘
    2020-12-09 00:34

    Alternately, you can use a single auto-generated VersionInfo.cs file that is referenced by all of the projects. To use this technique, strip out the version, company info, etc. attributes from your projects' AssemblyInfo.cs file (yes, this is a pain, but you only have to do this once), and have a batch command spit out a VersionInfo.cs file based on a template. To reference the common file in Visual Studio, you choose Add Existing Item from the project context menu, and after you've navigated to the VersionInfo.cs file in the file browser, click the drop-down arrow next to Add and select Add as Link.

    Below is an example of one I use. This script is checked into our SCC system and is executed at the beginning of the build, supplying %BUILD_NUMBER% to the script.

    SET BUILD=%1
    
    @echo using System.Reflection; > "%~p0Version.cs"
    @echo [assembly: AssemblyCompany("MyCompany, Inc.")] >> "%~p0Version.cs"
    @echo [assembly: AssemblyProduct("MyProduct")] >> "%~p0Version.cs"
    @echo [assembly: AssemblyCopyright("Copyright © 2012 MyCompany, Inc.")] >> "%~p0Version.cs"
    @echo [assembly: AssemblyTrademark("")]@echo [assembly: AssemblyVersion("1.0.%BUILD%.0")] >> "%~p0Version.cs"
    
    @echo [assembly: AssemblyFileVersion("1.0.%BUILD%.0")] >> "%~p0Version.cs"
    
    @echo ^ > "%~p0Version.wxi"
    @echo   ^ >> "%~p0Version.wxi"
    @echo ^ >> "%~p0\Version.wxi"
    

提交回复
热议问题