2

I am running Visual Studio 2015.

I have a utility library project that references a number of third party assemblies, which are all registered in the GAC. In that project, all of the dependencies that are registered in the GAC are references with copy local set to false. When I build that project, the GAC assemblies are not copied to the build directory.

The utility project is then referenced, as a project, by another project, with "copy local" set to true. Then the referencing project builds, all of the GAC assemblies referenced by the utility project are copied to the build directory. These assemblies are quite large and it really slows down the build and bloats the build directory.

Visual Studio 2013 did not do this. Secondary references that were registered in the GAC were not copied. I should also note that in Visual Studio 2015, the secondary references are also copied if I reference the utility project as a file rather than as a project. Is there a way to stop it from copying the secondary dependencies?

Here is a section of the Detailed output from MSBuild for one of the secondary references that is getting copied:

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".
Brian Reichle
  • 2,798
  • 2
  • 30
  • 34
  • Any update for this issue? Have you resolved this issue? If not, would you please let me know the latest information about this issue? – Leo Liu Nov 05 '18 at 01:21
  • I have not resolved the issue. I did change the MS Build output to Detailed, which yielded some interesting insights. For example, not every assembly referenced by the utility library is getting copied to the referencing projects build directory, but most of them are. The MSBuild output look the same for the ones that are copied and the ones that are not. It looks like the assemblies are not being found in the GAC, but Registry: ...AssemblyFoldersEx. I added an excerpt of the output for one of the secndary references that is getting copied to the question. – Preston McCormick Nov 05 '18 at 22:20

2 Answers2

2

I did eventually solve this issue. The solution was adding this section to the .csproj file for the secondary library projects:

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

How to stop Visual Studio from copying secondary references?

AFAIK, Copy Local = False should by itself be enough to prevent those third party assemblies from getting copied to the another project build directory. Which in turn prevents msbuild from finding those GAC assemblies when it builds another project. And it shouldn't be looking for it at all since GAC assemblies should no longer appear in the manifest of anther project. More than one thing went wrong here. To track this issue, you should change the MSBuild output log to Detailed to find out how it managed to find it anyway.

Change the MSBuild to detailed:

Under Tools –>Options –>Projects and Solutions –>Build and Run->MSBuild project build output verbosity, change the MSBuild project build output verbosity to Detailed or Diagnostic.

Besides, as a workaround, you can set those third party assemblies into a nuget package, not set them into the GAC, then add this nuget package to the another project, build the project, those third party assemblies would not copy to the bin folder of the another project.

Create nuget package from dlls

Hope this helps.

Leo Liu
  • 71,098
  • 10
  • 114
  • 135