Search code examples
.netvisual-studiocom-interop

Change name of output dll based on configuration


It seems like it should be simple enough, but basically I have two configurations for a class library. One is a normal .NET 4.0 configuration, the other is configured to register for COM Interop, and additionally defines a compilation symbol so I can work around some COM-related quirks with pre-processor directives.

The issue is that when deployed, both of these DLLs must be in the same folder for the calling application to be able to use them (by design, can't do much about it). I've got everything working great when compiling each configuration to its respective bin/ sub-folder, including signing both configs with different strong-name keys such that the GAC sees two different assemblies, even with the same name and version.

But putting them in the same folder requires that one needs renamed, and that's where the problem lies.

What would be terrific is if in Visual Studio I could conditionally set the Assembly Name property in the Application tab, but it looks like that tab is project-scoped, not config-scoped. Short of that, is there any way to specify a different file name such that won't cause run-time problems, not to mention developer sanity problems? My goal here is to be able to provide features to .NET clients that COM doesn't support, while still having compatibility with COM. I'd greatly prefer not to copy and paste everything into another project that just has a different Assembly Name...


Solution

  • You can do that by editing your .csproj file. Remove the <AssemblyName> element from the main <PropertyGroup> and put it in the respective configuration-specific PropertyGroups:

    <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
        <AssemblyName>StackOverflow26265487.Debug</AssemblyName>
        <!-- ... -->
    </PropertyGroup>
    <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
        <AssemblyName>StackOverflow26265487.Release</AssemblyName>
        <!-- ... -->
    </PropertyGroup>