Our company has been able to successfully modify the PE Header of our compiled binaries using a third-party tool called Resource Hacker over the last few years. It has been working really well for all C++ and C# binaries after the compilation process.
With the introduction of dotnet.exe publish
command as single-file
by Microsoft in our build process, several binaries are now packed into a single executable bundle file. We have noticed that any modification done to the PE Header of this executable bundle file AFTER the publish process invalidates this executable. Apparently, the executable itself has some sort of self-consistency-check to detect if it was modified after the publish command, and then stops its own execution.
We were still interested in filling some fields of the PE Header of the executable bundle file, for marking our company's name, copyright, trademarks, version, etc.
Apparently AssemblyInfo.cs
is not an available option anymore for .NET 6 applications, so we had to find another way. Please correct me if I am wrong here.
We stopped using the third-party Resource Hacker tool, and for the fields PRODUCT VERSION and FILE VERSION we just pass the following parameters directly to the dotnet.exe publish
command:
dotnet.exe publish ... -p:AssemblyVersion=1.2.3.4 -p:Version=1.02
This works correctly, and we do it so because our build can then set the version information dynamically accordingly with the build number.
For other static fields, we decided to use the following project file settings (in the *.csproj file):
<PropertyGroup>
...
<Company>DUMMY COMPANY</Company>
<Description>A dummy description for the assembly.</Description>
<Product>DUMMY PRODUCT</Product>
<Copyright>Copyright © DUMMY COMPANY. All rights reserved.</Copyright>
<LegalTrademarks>DUMMY COMPANY, DUMMY PRODUCT</LegalTrademarks>
...
</PropertyGroup>
The assembly now gets correctly marked for most PE Header fields, except for the "LegalTrademarks" field, which is missing, as shown in the image below:
This is how it should be:
Question:
Does anyone know how to set this "LegalTrademarks" field to the PE Header of the executable bundle file generated by the dotnet.exe publish
command for .NET Core and .NET 6 apps when publishing as single-file?
Feel free to provide more examples on how to set other additional fields too.