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.

Alias in ProjectReference does not work for framework-included packages

See original GitHub issue

Issue moved from NuGet/Home#10438


From @weltkante on Friday, January 8, 2021 4:19:41 PM

Details about Problem

In #4989 alias support for PackageReference was added, but when I try to create an alias to a framework-provided package this does not appear to work.

In particular, in a .NET 5 web application I add

<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="5.0.0" Aliases="logging" />

but extern alias logging; does not compile:

error CS0430: Der externe Alias "logging" wurde nicht in einer /reference-Option angegeben.

If I instead do it in a console application it indeed does work.

Using VS 2019 Update 9 Preview 2

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:13

github_iconTop GitHub Comments

1reaction
tdhatchercommented, Jan 30, 2023

This looks like a related issue. https://github.com/dotnet/msbuild/issues/4943

Problem Only the extern alias of the first occurrence of NuGet PackageReference is recognized v12. v11 results in compilation error CS0430

Reproduce Steps

  1. csproj
<ItemGroup>
    <PackageReference Include="Newtonsoft.Json" Version="12.0.3" Aliases="v12" />
    <PackageReference Include="Newtonsoft.Json" Version="11.0.2" Aliases="v11" />
</ItemGroup>
  1. Program.cs (C# 11 / NET 7)
extern alias v12;
extern alias v11;

using Json12 = v12::Newtonsoft.Json;
using Json11 = v11::Newtonsoft.Json;

Json12.JsonConvert.SerializeObject(new { message = "Hello, world!" });
Json11.JsonConvert.SerializeObject(new { message = "Hello, world!" });

I even stumped ChatGPT with this one, it seemed so confident that it should be working and that I was doing something wrong. image

0reactions
CodeOptimistcommented, Jun 28, 2023

Still busted, my project is net472.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to `extern alias` an assembly with .Net core?
I had a problem in .Net Core 2.2 where the MySqlConnector type name and namespace had a collision and the answer was to...
Read more >
PackageReference in project files - NuGet
Starting with NuGet 5.7 & Visual Studio 2019 Update 7, equivalent to ProjectReference, PackageReference supports Aliases . By default no aliases ...
Read more >
How to use two types across assemblies with the same ...
If you are using Visual Studio, it is very easy to setup an extern alias. Just right click on the respective dependency within...
Read more >
Unresolved references in error list to types in System.Web. ...
We reproduced the issue for projects that define an alias for a project reference. We are working on a fix.. Click to vote...
Read more >
How to Use 'Extern Alias' to differentiate assemblies that use ...
In order to use extern aliases, you first need to open the .csproj file of your project and modify the PackageReference or ProjectReference...
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