Search code examples
c#gitvisual-studiomultiple-versions

Maintain two C# projects versions


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


Solution

  • 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