How to read property value from external file?

后端 未结 5 1710
死守一世寂寞
死守一世寂寞 2021-01-04 09:54

I have AssemblyInfo.cs file automatically generated during build. Here\'s part of .csproj file:


    2
    &l         


        
5条回答
  •  醉梦人生
    2021-01-04 10:33

    It is possible to do this using the ability of PropertyFunctions to call certain .NET functions directly. Essentially, you can call File.ReadAllText() when setting a property value.

    
        $([System.IO.File]::ReadAllText("Version.txt"))
    
    
        
    
    
    
    

    The Version.txt file would just contain the first three version numbers, i.e. "1.2.3" or whatever.

    I'm not sure exactly when this was added to MSBuild, but it was probably after this question was asked and answered.

提交回复
热议问题