1

During a building of my binaries I am able to set lots of VERSIONINFO properties like FILEVERSION, PRODUCTVERSION and StringFileInfo, for example:

[assembly: AssemblyCompany("XXX")]
[assembly: AssemblyProduct("My Product")]
[assembly: AssemblyCopyright("© XXX, 2017")]
[assembly: AssemblyVersion("9.5")]
[assembly: AssemblyFileVersion("9.5.1001")]

My question is how to set FILEFLAGS field? In vcxproj I am including a rc-file with correct VERSIONINFO structure. Is similar possible for the csproj projects?

Note, I have a lots of csproj-projects and I don't want to add custom build step to every project file (as I can forget to do it in new projects).

Andrey
  • 927
  • 11
  • 12
  • See : https://stackoverflow.com/questions/8384426/write-file-extended-property-revision-number-on-all-type-of-files. Also pinvoke : https://www.pinvoke.net/default.aspx/kernel32.SetFileInformationByHandle – jdweng Mar 26 '18 at 08:59

2 Answers2

0

You can't set the FILEFLAGS with CSC (it's implicitly equal to 0). You can set the following though:

AssemblyInformationalVersion    /productversion
AssemblyVersion                 /version
AssemblyFileVersion             /version
AssemblyCopyright               /copyright
AssemblyCompany                 /company
AssemblyProduct                 /product
BanksySan
  • 27,362
  • 33
  • 117
  • 216
0

you can add a custom build action to your project file

in your csproj file add this line

<Import Project="Properties\build.targets" />

build.targets file

<?xml version="1.0" encoding="utf-8" ?>
<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="$(ProjectDir)..\packages\MSBuildTasks.1.5.0.235\tools\MSBuild.Community.Tasks.Targets" />
  <Import Project="$(ProjectDir)..\packages\MSBuild.Extension.Pack.1.9.1\build\net40\MSBuild.Extension.Pack.targets"/>

  <!-- Overriding the Microsoft.CSharp.targets target dependency chain -->
  <!-- Call our custom AssemblyVersion target before build, even from VS -->
  <PropertyGroup>
    <BuildDependsOn>
      AssemblyVersion;
      $(BuildDependsOn)
    </BuildDependsOn>
    <CompanyName>My Company</CompanyName>
    <Copyright>Copyright © My Company 2017</Copyright>
    <Title>My Project </Title>

  </PropertyGroup>


    <ItemGroup>
      <AssemblyVersionFiles Include="$(MSBuildProjectDirectory)\Properties\AssemblyInfo.cs"/>
    </ItemGroup>



    <Target Name="AssemblyVersion"
            Inputs="@(AssemblyVersionFiles)"
            Outputs="UpdatedAssemblyVersionFiles">

      <Attrib Files="%(AssemblyVersionFiles.FullPath)"
              Normal="true"/>

      <Message Importance="High" Text="-------------------------------------------------------------------------"/>
      <Message Importance="High" Text="[@(AssemblyVersionFiles)]"/>
      <Message Importance="High" Text="-------------------------------------------------------------------------"/>

      <MSBuild.ExtensionPack.Xml.XmlFile TaskAction="ReadAttribute" File="$(SolutionDir)AnyFolder\data.xml"
                                         XPath="//Config/VersionNum/@value">
        <Output PropertyName="ExecutableVersion" TaskParameter="Value"/>
      </MSBuild.ExtensionPack.Xml.XmlFile>

      <AssemblyInfo
        CodeLanguage="CS"
        OutputFile="%(AssemblyVersionFiles.FullPath)"
        AssemblyCompany="$(CompanyName)"
        AssemblyCopyright="$(Copyright)"
        AssemblyVersion="$(ExecutableVersion)"
        AssemblyFileVersion="$(ExecutableVersion)"
        AssemblyTitle="$(Title)"
        AssemblyProduct="$(Title)"
        ComVisible="false"
        AssemblyDescription=""
        AssemblyConfiguration=""
        AssemblyTrademark=""
        AssemblyCulture="">
        <Output TaskParameter="OutputFile"
                ItemName="UpdatedAssemblyVersionFiles"/>
      </AssemblyInfo>
    </Target>

</Project>

it also includes how to log some info to the output window and even read an xml file to get the version of your application

Ben Croughs
  • 2,566
  • 1
  • 20
  • 30