Home > OS >  Maintain two C# projects versions
Maintain two C# projects versions

Time:06-02

I've got an app that connects to a program. So it's a plugin basically. And the program it attaches to has different versions (2021, 2022, 2023). To use API I have to reference to appropriate .dll file. And these references are the only things that changes. So the source code is the same in all my plugin's versions, but I have to change these references. How can I do that efficiently? Copying code between projects with different dlls attached isn't the best solution I guess... I'm using MS Visual Studio. Is it best to do it with git (how?) or maybe VS itself has some tools to achieve that?

Please help me, Przemek

CodePudding user response:

Visual Studio allows you to create a so-called shared project. It's similar to a library, but it's not compiled on its own: Its source files are considered part of each project that references the shared project.

Your solution structure should look as follows:

  • Plugin2021
  • Plugin2022
  • Plugin2023
  • SharedProject

Your shared project would contain all the code, your plugin projects would contain only a reference to the corresponding API dll and to the shared project.

CodePudding user response:

So I created different configurations for my project - one or two for every version and then conditionally referenced to needed .dll in .csproj file.

In ItemGroup I have now many of tags like this:

 <Reference Include="autodesk.inventor.interop, Version=26.0.0.0, Culture=neutral, PublicKeyToken=d84147f8b4276564, processorArchitecture=MSIL" Condition="'$(Configuration)' == 'Release' OR '$(Configuration)' == 'Debug'">
  <SpecificVersion>False</SpecificVersion>
  <EmbedInteropTypes>False</EmbedInteropTypes>
  <HintPath>C:\Windows\Microsoft.NET\assembly\GAC_MSIL\Autodesk.Inventor.Interop\v4.0_26.0.0.0__d84147f8b4276564\autodesk.inventor.interop.dll</HintPath>
</Reference>

And it seems to work just fine. Some more modifications with TargetPath and I'm good to go! Thanks a lot to everyone for your time.

Przemek

  • Related