question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

New .csproj cannot reference GAC assemblies

See original GitHub issue

From @jnm2 on March 13, 2017 20:31

You can no longer reference some GAC assemblies without specifying a HintPath, at which point there isn’t much point in using the GAC at all.

Class1.cs:

using System;
using Microsoft.SolverFoundation.Services;

public class Class1
{
    public static readonly Type X = typeof(ISolver);
}

Old .csproj, working:

<Project ToolsVersion="15.0">
  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" />
  <PropertyGroup>
    <OutputType>Library</OutputType>
    <TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
    <OutputPath>bin\$(Configuration)\</OutputPath>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="Microsoft.Solver.Foundation" />
  </ItemGroup>
  <ItemGroup>
    <Compile Include="*.cs" />
  </ItemGroup>
  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

New .csproj fails to find the reference:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net462</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <Reference Include="Microsoft.Solver.Foundation" />
  </ItemGroup>

</Project>

This also does not work: <Reference Include="Microsoft.Solver.Foundation, Version=3.0.2.10889, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />.

Why is this broken?

Copied from original issue: dotnet/roslyn-project-system#1739

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:2
  • Comments:17 (11 by maintainers)

github_iconTop GitHub Comments

9reactions
davkeancommented, Mar 14, 2017

From @jnm2 on March 13, 2017 23:11

Adding this to the bottom of the new csproj and reopening the solution fixes all problems:

  <!-- Workaround for https://github.com/dotnet/roslyn-project-system/issues/1739 -->
  <PropertyGroup>
    <AssemblySearchPaths>$(AssemblySearchPaths);{GAC}</AssemblySearchPaths>
  </PropertyGroup>
2reactions
davkeancommented, Mar 14, 2017

In SDK-based projects {GAC} is no longer part of the search paths. GAC is a runtime-lookup location, not a build-time lookup location. This is a deliberate change - it resulted in a huge number of bugs where projects would accidentally pick up the wrong dependencies on build machines because a targeting pack or SDK wasn’t installed. I suspect when you add a version number, you are resolving it from a build-time location such as {AssemblyFoldersEx} instead of the GAC. Looking at the build log would help us figure that out.

As you found, the workaround is to explicitly add {GAC} to the set of search paths.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Reference GAC assemblies in new CSPROJ format?
So I found this thread on GitHub which indicates <Reference> not discovering assemblies added to the GAC is expected behavior:.
Read more >
MSB3277: Found conflicts between different versions of ' ...
This error occurs during a build when more than one version of the same dependent assembly is referenced in a build of the...
Read more >
Add references in the Reference Manager - Visual Studio ...
NET assemblies that are available for referencing. The Assemblies tab doesn't list any assemblies from the global assembly cache (GAC) because ...
Read more >
the type is defined in an assembly that is not referenced error
Fixing: the type is defined in an assembly that is not referenced error · 1. Add the reference DLL that contains the type...
Read more >
VS2019 16.3.4 Build problem
This usually happens (the specific error messages you shared) when you have msbuild assemblies in the gac. Please run the following script and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found