简体   繁体   English

如何在Visual Studio中设置解决方案的引用路径?

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

I have a C# solution contains many projects. 我有一个C#解决方案包含很多项目。 Each project references some dlls in a specified folder. 每个项目都引用指定文件夹中的一些dll。 According to MSDN we could add the reference path for a project in project -> Properties -> Reference Paths. 根据MSDN,我们可以在项目 - >属性 - >参考路径中添加项目的参考路径。 It will generate a .csproj.user file under the project folder with the content below: 它将在项目文件夹下生成一个.csproj.user文件,其中包含以下内容:

<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: 打开包管理器控制台(例如,查看|其他Windows |包管理器控制台),并使用以下脚本作为相对路径:

$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"}

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Visual Studio中添加多个解决方案参考 - How to add multiple solution reference in Visual Studio 如何引用添加到Visual Studio解决方案的项目? - How do I reference items that I add to Visual Studio solution? 如何在visual studio 2013解决方案资源管理器中获取文件路径? - How to get a file path in visual studio 2013 solution explorer? Visual Studio扩展:如何在选择时获取解决方案文件夹的“路径”? - Visual Studio Extension: How to get the “path” of a solution folder on selection? 当我在同一解决方案中卸载项目时,Visual Studio 中的引用路径不起作用 - Reference Path in Visual Studio not working when I unload the project in the same solution 具有多个项目的Visual Studio解决方案:参考路径 - Visual Studio Solution with Multiple Projects: Reference Paths 如何在Visual Studio 2017解决方案中设置文件夹以在其中搜索DLL? - How to set folder in a visual studio 2017 solution for searching DLLs there? 如何在 Visual Studio 中设置要发布的构建目标和解决方案? - How to set up build target to release and the solution in Visual Studio? 如何使用 CMake 为 Visual Studio 解决方案设置程序集引用? - How to set assembly references for Visual Studio solution using CMake? 如何为Visual Studio解决方案设置选项卡? - How can I set tabs for Visual Studio solution?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM