【问题标题】:How to stop Visual Studio from copying secondary references?如何阻止 Visual Studio 复制辅助引用?
【发布时间】:2019-04-05 22:42:21
【问题描述】:

我正在运行 Visual Studio 2015。

我有一个实用程序库项目,它引用了许多第三方程序集,这些程序集都在 GAC 中注册。在该项目中,在 GAC 中注册的所有依赖项都是将本地复制设置为 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".

【问题讨论】:

  • 这个问题有什么更新吗?你解决了这个问题吗?如果没有,请告诉我有关此问题的最新信息吗?
  • 我还没有解决这个问题。我确实将 MS Build 输出更改为详细,这产生了一些有趣的见解。例如,并非实用程序库引用的每个程序集都被复制到引用项目的构建目录中,但大多数都是。 MSBuild 输出对于复制的和未复制的输出看起来相同。看起来在 GAC 中找不到程序集,但在注册表中找到:...AssemblyFoldersEx。我为复制到问题中的一个辅助参考添加了输出摘录。

标签: visual-studio-2015 msbuild dependencies


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

    如何阻止 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项目构建输出详细程度更改为DetailedDiagnostic。

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

    Create nuget package from dlls

    希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-09-18
      • 2012-12-06
      • 1970-01-01
      • 2014-08-21
      • 2013-02-19
      • 2013-08-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多