简体   繁体   中英

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?

I found a blog post explaining how to do this.

Open the Package Manager Console (eg 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"}

我不相信,可能是因为可以将项目加载到许多解决方案中,并且如果所需库的参考路径成为解决方案的范围,您最终会遇到构建错误或不同的行为,具体取决于您使用哪种解决方案如果解决方案告诉项目在不同的位置查找依赖项,则构建项目。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM