How to create different DLLs in one project?

I have a question that I do not know if it can be resolved. I have one C # project in Visual Studio 2005, and I want to create different DLL names depending on the preprocessor constant. At this moment I have a preprocessor constant, two snk files and two guid collectors. I also create two configurations (Debug and Debug Preprocessor), and they compile fine using the appropriate snk and guid.

#if PREPROCESSOR_CONSTANT
[assembly: AssemblyTitle("MyLibraryConstant")]
[assembly: AssemblyProduct("MyLibraryConstant")]
#else
[assembly: AssemblyTitle("MyLibrary")]
[assembly: AssemblyProduct("MyLibrary")]
#endif

Now I have to put two assemblies in the GAC. The first assembly was added without problems, and the second is not.

What can I do to create two or more different assemblies from the same Visual Studio project?

Is it possible that I forgot to include a new line in "AssemblyInfo.cs" to change the name of the DLL depending on the preprocessor constant?

+3
4

Post-Build:

if "$(ConfigurationName)" == "Debug" goto Debug
if "$(ConfigurationName)" == "Release" goto Release

goto End

:Debug
del "$(TargetDir)DebugOutput.dll"
rename "$(TargetPath)" "DebugOutput.dll"

:Release
del "$(TargetDir)ReleaseOutput.dll"
rename "$(TargetPath)" "ReleaseOutput.dll"

:End

DebugOutput.dll ReleaseOutput.dll . "Debug" "Release" .


script dll ; AssemblyNames, .

:

Name <,Culture = CultureInfo> <,Version = Major.Minor.Build.Revision> <, StrongName> <,PublicKeyToken> '\0'

, , .

:

  • :

    #if SOME_COMPILER_SYMBOL
    [assembly: AssemblyVersion("1.0.0.0")]
    #else
    [assembly: AssemblyVersion("1.0.0.1")]
    #endif
    
  • - sn AssemblyInfo.cs:

    #if SOME_COMPILER_SYMBOL
    [assembly: AssemblyKeyFile("FirstKey.snk")]
    #else
    [assembly: AssemblyKeyFile("SecondKey.snk")]
    #endif
    

, GAC, , .

+4

Visual Studio . script. MSBuild script , .

, .csproj:

<Target Name="AfterBuild">
    <Copy SourceFiles="$(OutputPath)\YourAssembly.dll" DestinationFiles="$(OutputPath)\YourAssemblyRenamed.dll"/>
    <Delete Files="$(OutputPath)\YourAssembly.dll"/>
</Target>
+3

, . .csproj, BeforeBuild :

<Target Name="BeforeBuild">
    <AssemblyName Condition="'$(Configuration)' == 'Release'">MyReleaseName</AssemblyName>
    <AssemblyName Condition="'$(Configuration)' == 'Debug'">MyDebugName</AssemblyName>
</Target>
+1

I think there is no such way. The name of the output assembly is strictly fixed in the project settings: one assembly per project.

Also, the AssemblyAttributes you specify only indicates the visible properties of the assembly (for example, in Windows Explorer), and not the file name.

-1
source

Source: https://habr.com/ru/post/1704126/


All Articles