New (Advanced) C# Compiler Options For Setting Certain COFF Flags/Characteristics?

Topics: General
Apr 6, 2014 at 2:40 PM
Hi,

I help maintain the .NET build system at my work, and there are a number of customisations built into the TFS build process we use that handle a number of common tasks across teams during assembly compilation, that are otherwise fiddly and/or time consuming to setup as they can't be done easily via Visual Studio projects. There's also some we do to increase the traceability of the compiled output.

These customisations include:
  1. Setting /LARGEADDRESSAWARE on 32-bit .exe files if an MSBuild property is set.
  2. Applying flags such as VS_FF_PRERELEASE into the Win32 resources.
  3. Building custom string-value pairs into the Win32 resource file, such as the changeset, date etc. for easy viewing in the file details without special tools.
Option 1 requires running the linker on the compiled binary, so using SignTool needs to be run at the right time so it is done after any additional post-processing, otherwise the signature gets corrupted due to the flag change.

2 and 3 require an entire custom Win32 resource file to be used, meaning that the compiler's built-in ability to insert the version, details, company name etc. from the assembly attributes is lost. It also stops the icon specified on the command-line from being included correctly.

It would be a lot easier to do things like this if the options existed at the compiler/MSBuild task level, rather than forcing the invoking of special tools and/or dynamic content generation in advance.

Would you consider a pull request that would add additional (advanced) options to CSC to allow at least some of these things to be easily accomplished?

I've been looking through the code and found where LARGEADDRESSAWARE is handled for example, as well as where the characteristics are written for the Win32 resources.

For example, a new command line argument that forced the compiled assembly to be LARGEADDRESSAWARE by setting the flag when the assembly is written.

I'm sure this is very low down a list of priorities/pain-points, as maybe these would have been added as features as very long time ago, hence I was thinking of adding this myself. However, there's no point at my starting to implement this if there's no interest on your side from making such features available.

As I mentioned, this has all now been implemented via custom MSBuild scripting and resource generation, but at the time it was done, this would have been a lot easier to do if there had just been a few csc arguments that could have been specified instead.

Thanks,
Martin
Developer
Apr 18, 2014 at 9:21 PM
Edited Apr 18, 2014 at 9:31 PM
Hi Martin,

Thanks for the suggestion. I can address the LARGEADDRESSAWARE piece only at this time. Roslyn compilers already add the LARGEADDRESSAWARE bit to all assemblies unless the platform is x86. See http://source.roslyn.codeplex.com/#Microsoft.CodeAnalysis/PEWriter/PeWriter.cs
  • Paul