Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What do you do about references when unloading a project in Visual Studio?

When you unload a project in Visual Studio, any referencing projects get warning triangles on their reference to the unloaded project. I've written myself a macro to do clever stuff (detect add/remove of project and transform any references from-to file/project dependency), but I can't believe that I'm not missing something much simpler. How can the unload function be any use if I have to go around manually changing references (and it breaks the 'personal solutions/shared projects' team development paradigm).

(This question is related to answers to this question about structuring large solutions in Visual Studio - some answers mentioned having solutions with lots of projects, but 'unloading' unused projects to improve performance.)

like image 278
Benjol Avatar asked Oct 07 '08 05:10

Benjol


People also ask

How do I resolve references in Visual Studio?

To fix a broken project reference by correcting the reference path. In Solution Explorer, right-click your project node, and then select Properties. The Project Designer appears. If you're using Visual Basic, select the References page, and then click the Reference Paths button.

How do I fix an unloaded project in Visual Studio?

Right click on the project folder and click Reload project.

What does unloading a project do in Visual Studio?

It can be useful to unload a project from a solution while resolving circular dependencies between projects or conflicts with different versions of the . NET framework between projects. It is considerably more difficult and error-prone to directly edit the configuration files with Notepad. Save this answer.


4 Answers

For my projects, I create an assemblies folder which the projects automatically copy into from a set location to which other projects copy builds.

Post-build for referenced assembly's project:

if not exist "C:\builds\Project1" md "C:\builds\Project1\"
copy "$(TargetDir)$(TargetName).*" "C:\builds\Project1\"

Pre-build for referencing projects:

if exist "c:\builds\Project1\" copy "c:\builds\Project1*.*" "$(ProjectDir)assemblies"

The project file points to its assemblies subfolder for references so even if the source projects are unloaded from the solution, the last-built assemblies will be used without the performance problems of having the whole project in memory while developing.

like image 53
Mark Cidade Avatar answered Sep 30 '22 14:09

Mark Cidade


What are the advantages of having projects in the same solution if you use file references?

If your app.exe uses utils.dll and you change the code for utils.dll, then if it's in the same solution VS will notice the dependency and recompile both. If it's not in the solution you'll have to jump out, recompile utils.dll seperately, then jump back in and recompile app.exe.

This becomes either more or less important depending on how many other dll's your exe is referencing, and how often they change (in team environments shared dll's change often in my experience).
There is also the side effect that if you have 100 projects in VS it will take a long time to process them all just to figure out if they need recompiling or not.

like image 42
Orion Edwards Avatar answered Sep 30 '22 13:09

Orion Edwards


Unloading projects is meant to be a temporary action so you can edit the actual project file as XML (text). If you want to completely remove a project from your solution, you should use the "Remove" menu option, which will take care of removing any references to that project.

One advantage to using project references is that it allows you to easily debug through the code. It also automatically ensures that you are using the correct configuration build (ie, if you are building in "Debug" mode it will use the Debug version of the assembly). That being said, you loose some determinisim about which version/build of the dependent project you will pick up - project references mean you always use the latest.

Yes, for Visual Studio to determine build dependencies it must be able to see and build all of the projects which would mean project references.

like image 35
Scott Dorman Avatar answered Sep 30 '22 14:09

Scott Dorman


I've just had a eureka moment reading through MSDN doc on structuring solutions and projects.

What I hadn't noticed is that in a multi-project solution, the context menu in the Solution Explorer proposes a Project Dependencies popup. Here you can define the project dependencies manually, if you haven't defined them by project references between projects.

See here (MSDN link, so will self destruct after a few weeks)

like image 35
Benjol Avatar answered Sep 30 '22 14:09

Benjol