c# – Reference a project from another solution without building it


I created 2 solutions:

  • Solution 1 with Console Application 1
  • Solution 2 with Class Library 2

Class Library 2 will be a helper used by several other solutions. I added the nlog library there:
enter image description here

I want the Console Application 1 project to use the functions from Class Library 2. As far as I know, I can do this in 2 ways:

  • a) build Class Library 2 and add a reference to the .dll file generated after building the project in the Console Application 1 project
  • b) add the Class Library 2 project to Solution 1 and then add a project reference to Class Library 2 in the Console Application 1 project within the same solution

I prefer option b), which looks like this now:
enter image description here

The problem now is: When I use .NET Framework 4.8, when I open Solution 1, I see the following errors:

The name 'NLog' does not exist in the current context
Metadata file '...\Desktop\experiment\`.NET Framework 4.8`\ClassLibrary1\ClassLibrary1\bin\Debug\ClassLibrary1.dll' could not be found
The referenced component 'NLog' could not be found.

The solution to this is to open Solution 2 and build it. Then Solution 1 no longer shows any errors. When I do the same in .NET 8.0, there is no problem — there’s no need to build Solution 2.

I uploaded an example in both .NET versions here: https://github.com/westpop/experiment/tree/main

Does anyone have a solution for this? I know it’s an old version of .NET Framework, but I’m trying to manage it in legacy code — I don’t want to have to build all the other solutions. I want the projects to work “out of the box.” Overall, I have no idea why this doesn’t work — after all, what difference does it make whether I build the project from one solution or another?

It seems to me that the solution would be to also keep the packages folder in the repository, but that probably isn’t a good practice.

Leave a Reply

Your email address will not be published. Required fields are marked *