You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
How to add extern alias for three same namspace assemblies #39
If you need to debug, I suggest running a build with the -bl option (dotnet build -bl or msbuild -bl), then open the msbuild.binlog file with the MSBuild binary log viewer. You can then look around to understand why the ReferencePath items are not getting the correct aliases metadata.
My example shows the concept. I don't know two packages on nuget.org that contain types in the same namespace, so I used NuGet.Versioning and NuGet.Frameworks as an example. But you can see in the C# file that it uses alias1 and alias2 and the code compiles, meaning the compiler was passed both alias names.
As I mentioned in the last paragraph of my example, you can use MSBuild's binary logs to check the ReferencePath items have the correct metadata:
Similarly on the Csc task, I can see /reference:alias1=C:\git\test\globalPackages\nuget.frameworks\5.5.0\lib\netstandard2.0\NuGet.Frameworks.dll /reference:alias2=C:\git\test\globalPackages\nuget.versioning\5.5.0\lib\netstandard2.0\NuGet.Versioning.dll
If you're getting the same alias on the assembly from different packages, I assume that you removed the AND '%(ReferencePath.NuGetPackageId)' == 'NuGet.Frameworks' part of the condition.
You can also add <Message Text="whatever" to add tracing information to help you debug your target.
In case it helps, msbuild doesn't know anything about .NET namespaces, that's a compiler issue. MSBuild is just a scripting language to run a bunch of tasks (the compiler is one task), by getting lists of files and generating task input parameters. So, it has no way of knowing whether two assemblies you want to use aliases on have the same or different namespaces inside.
Activity
zivkan commentedon Mar 25, 2020
Try something like this
Change the assembly and package ids as necessary.
dhinesh-v commentedon Mar 26, 2020
Hi @zivkan ,
I have tried your solution, but only one alias is working, Other aliases are not working and showing below error,
The extern alias 'LatestCore' was not specified in a /reference optionAlso I have tried below solution,
But same problem happens.
zivkan commentedon Mar 26, 2020
This worked for me at build, but intellisense doesn't know about the aliases
If you need to debug, I suggest running a build with the
-bloption (dotnet build -blormsbuild -bl), then open themsbuild.binlogfile with the MSBuild binary log viewer. You can then look around to understand why the ReferencePath items are not getting the correct aliases metadata.dhinesh-v commentedon Mar 27, 2020
@zivkan Thank you so much for helping me here, I'm really sorry that i didn't clearly explain the issue.
I can able to alias two assemblies which has different namespace. But i want to alias three assemblies which have same namespace.
zivkan commentedon Mar 27, 2020
My example shows the concept. I don't know two packages on nuget.org that contain types in the same namespace, so I used
NuGet.VersioningandNuGet.Frameworksas an example. But you can see in the C# file that it usesalias1andalias2and the code compiles, meaning the compiler was passed both alias names.As I mentioned in the last paragraph of my example, you can use MSBuild's binary logs to check the ReferencePath items have the correct metadata:
Similarly on the
Csctask, I can see/reference:alias1=C:\git\test\globalPackages\nuget.frameworks\5.5.0\lib\netstandard2.0\NuGet.Frameworks.dll /reference:alias2=C:\git\test\globalPackages\nuget.versioning\5.5.0\lib\netstandard2.0\NuGet.Versioning.dllIf you're getting the same alias on the assembly from different packages, I assume that you removed the
AND '%(ReferencePath.NuGetPackageId)' == 'NuGet.Frameworks'part of the condition.You can also add
<Message Text="whatever"to add tracing information to help you debug your target.zivkan commentedon Mar 27, 2020
Closing as you're also engaging with us at NuGet/Home#4989
In case it helps, msbuild doesn't know anything about .NET namespaces, that's a compiler issue. MSBuild is just a scripting language to run a bunch of tasks (the compiler is one task), by getting lists of files and generating task input parameters. So, it has no way of knowing whether two assemblies you want to use aliases on have the same or different namespaces inside.