-1

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

Arrdiss
  • 7
  • 3
  • 1
    Have you tried using conditional compilation and compiler directives? In `csproj` you can add conditions to an `ItemGroup` or `PropertyGroup` element, allowing you to use different references or settings for different targets and releases. That's how different `Debug` and `Release` configurations work. In your source code you can use [preprocessor directives](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/preprocessor-directives) to compile different code under different conditions – Panagiotis Kanavos Jun 01 '22 at 07:26
  • 1
    Please read the "how to ask a question" guide. you are supposed to provide code examples of what you have tried, etc. This task too loosely formulated to give a proper response – Morten Bork Jun 01 '22 at 07:28
  • @MortenBork: I disagree. How is a code example supposed to help if OP asks about how to structure their source code files? (Usually, I'm really quick to vote to close if no mcve is provided, but this question is one of the rare exceptions where it just makes no sense.) – Heinzi Jun 01 '22 at 11:42
  • @Heinzi 1: It will show that the ask'er tried something, and isn't just using this as a proxy developer. 2: It can give a hint to something specific that may or may not have been overlooked. 3: "How can I do that efficiently", well compared to what? With no baseline, any solution is technically efficient. 4: "I've got an app that connects to a program. So basically a plugin" that isn't basically a plug, an API connects, a queue connects, a db connects, the OS conncts. a DLL connects. But it's either, not default 1 of them. – Morten Bork Jun 02 '22 at 05:13
  • @Heinzi "To use API, I have to reference appropriate .dll file" What dll file is he talking about? You can normally use an API, without using anything but native code. "And these references are the only things that changes" What references are changing? and why? the source code is the same in all his plugins versions? Ooookay. Then no references are changing? Or is he talking about the location of the .dll on disk? Copying code between projects? What code? DLL's? Source files? what? – Morten Bork Jun 02 '22 at 05:17
  • @Heinzi The guide is there to help make your question clear, prove that you have a vested interest in the answer, and take make it easy for anyone willing to spend time reading the question to answer you, if they have the capacity to do so. Not writing a proper question, is just rude. – Morten Bork Jun 02 '22 at 05:19
  • @Heinzi and seeing their current structure, will likely help any mentor, to give specific advice instead of a general answer, that may or may not work, based on the specifics. (Which incidently weren't provided) – Morten Bork Jun 02 '22 at 05:22
  • Thanks for help and advices. Conditional including references helped, thanks @PanagiotisKanavos! – Arrdiss Jun 02 '22 at 07:56

2 Answers2

0

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.

Heinzi
  • 167,459
  • 57
  • 363
  • 519
0

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

Arrdiss
  • 7
  • 3