0

I'm deploying a .NET application library DLLs with Visual Studio / msbuild. This library has many configurations for the multiple platforms it targets. I need to find a way to export some of the configuration data along each build, because the container that loads these DLL's has to be able to know which suits each platform.

I tried using custom assembly attributes, but these require the assemblies to be loaded, which I can't do (even with ReflectionOnlyLoad): I need to analyze each assembly before loading it, specifically to determine whether it should be loaded at all.

One solution would be to create a companion "meta" file to the DLL, who's content would be generated depending on preprocessor directives, for example:

Configuration.txt:

#if AOT
    AotCompile
#endif

#if NETFX_CORE
    DotNetCore
#endif

#if NO_THREADS
    NoThreads
#endif

After Googling I thought I could use T4 Text Templates, but it seems like they cannot access compilation symbols (and the workaround suggested in that question cannot work in my build pipeline). There is this answer which offers a solution, but it involves manually editing each project file's XML, which is incredibly time consuming considering I have many projects.

Is there another way to export some or all of the configuration data when building?

Community
  • 1
  • 1
Lazlo
  • 8,518
  • 14
  • 77
  • 116

1 Answers1

0

One simpler solution I found is to add this post-build event:

echo $(DefineConstants) > "$(TargetDir)\$(TargetName).defines"

Which outputs the defines, e.g. TRACE;DEBUG in a file name MyProject.defines alongside the DLL.

Lazlo
  • 8,518
  • 14
  • 77
  • 116
  • I'm not marking this as the answer yet, I'm curious to see if others can find a better approach. – Lazlo Mar 20 '17 at 21:53