如何阻止Visual Studio复制辅助引用?

时间:2018-11-01 16:53:34

标签: visual-studio-2015 msbuild dependencies

我正在运行Visual Studio 2015。

我有一个实用程序库项目,该项目引用了许多在GAC中注册的第三方程序集。在该项目中,在GAC中注册的所有依赖项都是将copy local设置为false的引用。当我构建项目时,GAC程序集不会复制到构建目录。

然后,另一个项目将实用程序项目作为一个项目引用,并且“本地复制”设置为true。然后,在引用项目的构建过程中,该实用程序项目引用的所有GAC程序集均被复制到构建目录中。这些程序集很大,并且确实减慢了构建速度并使构建目录膨胀。

Visual Studio 2013未执行此操作。未复制在GAC中注册的二级参考文献。我还应注意,在Visual Studio 2015中,如果我将实用程序项目作为文件而不是项目进行引用,也会复制辅助引用。有没有办法阻止它复制辅助依赖项?

这是MSBuild的“详细”输出的一部分,其中包含要复制的辅助引用之一: 4> Dependency "ESRI.ArcGIS.Catalog, Version=10.5.0.0, Culture=neutral, PublicKeyToken=8fc3cc631e44ad86". 4> Resolved file path is "C:\Program Files (x86)\ArcGIS\DeveloperKit10.5\DotNet\ESRI.ArcGIS.Catalog.dll". 4> Reference found at search path location "{Registry:Software\Microsoft.NETFramework,v4.7.2,AssemblyFoldersEx}". 4> For SearchPath "C:...\bin\Release". 4> Considered "C:...\bin\Release\ESRI.ArcGIS.Catalog.winmd", but it didn't exist. 4> Considered "C:...\bin\Release\ESRI.ArcGIS.Catalog.dll", but it didn't exist. 4> Considered "C:...\bin\Release\ESRI.ArcGIS.Catalog.exe", but it didn't exist. 4> For SearchPath "{TargetFrameworkDirectory}". 4> Considered "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.7.2\ESRI.ArcGIS.Catalog.winmd", but it didn't exist. 4> Considered "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.7.2\ESRI.ArcGIS.Catalog.dll", but it didn't exist. 4> Considered "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.7.2\ESRI.ArcGIS.Catalog.exe", but it didn't exist. 4> Considered "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.7.2\Facades\ESRI.ArcGIS.Catalog.winmd", but it didn't exist. 4> Considered "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.7.2\Facades\ESRI.ArcGIS.Catalog.dll", but it didn't exist. 4> Considered "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.7.2\Facades\ESRI.ArcGIS.Catalog.exe", but it didn't exist. 4> For SearchPath "{Registry:Software\Microsoft.NETFramework,v4.7.2,AssemblyFoldersEx}". 4> Considered AssemblyFoldersEx locations. 4> Required by "C:...\bin\Release\ArcBase.dll". 4> Found related file "C:\Program Files (x86)\ArcGIS\DeveloperKit10.5\DotNet\ESRI.ArcGIS.Catalog.xml". 4> The ImageRuntimeVersion for this reference is "v4.0.30319".

2 个答案:

答案 0 :(得分:0)

  

如何阻止Visual Studio复制辅助引用?

AFAIK,Copy Local = False本身应足以防止将那些第三方程序集复制到另一个项目构建目录中。反过来,这会阻止msbuild在构建另一个项目时查找那些GAC程序集。而且它根本不应该寻找它,因为GAC程序集不应再出现在其他项目的清单中。这里有不止一件事出了错。要跟踪此问题,您应该将MSBuild输出日志更改为“详细”,以了解它如何设法找到它。

将MSBuild更改为详细信息:

Tools –> Options –> Projects and Solutions –> Build and Run-> MSBuild project build output verbosity下,将MSBuild项目构建输出的详细程度更改为 Detailed 诊断

此外,作为一种解决方法,您可以将这些第三方程序集设置为nuget程序包,而不是将其设置为GAC,然后将该nuget程序包添加到另一个项目中,构建该项目,这些第三方程序集不会复制到另一个项目的bin文件夹。

Create nuget package from dlls

希望这会有所帮助。

答案 1 :(得分:0)

我最终解决了这个问题。解决方案是将本节添加到辅助库项目的.csproj文件中:

<Project... >
    <PropertyGroup>
        <DoNotCopyLocalIfInGac>true</DoNotCopyLocalIfInGac>
    </PropertyGroup>