Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the reference path for the solution in Visual Studio?

I have a C# solution contains many projects. Each project references some dlls in a specified folder. According to MSDN we could add the reference path for a project in project -> Properties -> Reference Paths. It will generate a .csproj.user file under the project folder with the content below:

<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <PropertyGroup>
        <ReferencePath>C:\References\bin\</ReferencePath>
    </PropertyGroup>
</Project>

But this only works for one project alone. Is there a simple way to apply the same setting to all of the projects in the solution?

like image 245
earlybird Avatar asked May 14 '12 03:05

earlybird


People also ask

What is reference path in Visual Studio project?

If you now view the properties for Project B, notice that the Reference Path property setting contains an entry that is the full path to the Project A Bin directory. The Reference Path property tells Visual Studio where to look for referenced assemblies; the default is the path you used when you added the reference.

How do I add a reference to a Visual Studio solution?

Add a reference Reference Manager opens and lists the available references by group. Select a reference to add, and then select OK. If you don't see the reference you're looking for, select Browse to locate the reference. (If you're developing C++ projects, you might not see a browse option.)

How do I reference in Visual Studio?

You can also right-click the project node and select Add > Project Reference. If you see a References node in Solution Explorer, you can use the right-click context menu to choose Add Reference. Or, right-click the project node and select Add > Reference.

How do I add a project reference in Visual Studio 2022?

Complete the following steps to add an assembly reference in Microsoft Visual Studio. Select the project in the Solution Explorer. Select Project»Add Reference to launch the Add Reference dialog box.


1 Answers

I found a blog post explaining how to do this.

Open the Package Manager Console (e.g. View | Other Windows | Package Manager Console) and use a script such as the following for relative paths:

$path = [System.IO.Path]; foreach ($proj in get-project -all) {$proj.Properties.Item("ReferencePath").Value="$($path::GetDirectoryName($proj.filename))\..\libs"}

or this for a single fixed project reference for all projects:

foreach ($proj in get-project -all) {$proj.Properties.Item("ReferencePath").Value="C:\lib"}
like image 97
Matthew Strawbridge Avatar answered Sep 22 '22 07:09

Matthew Strawbridge