如何使用 .Net 核心`extern alias` 程序集? [英] How to `extern alias` an assembly with .Net core?
问题描述
TLDR:所有内容都在标题中.
TLDR: Everything is pretty much in the title.
假设您的 project.json
使用了两个包,它们具有两种名称相同的类型(名称相同,命名空间相同).
Suppose that your project.json
uses two packages that have a two types which are named the same (same name, same namespace).
如何使用其中一种类型?
How to use one of thoses types ?
使用 .Net 分类,这很容易.只需使用 extern 别名.
With classing .Net, that's easy. Just use an extern alias.
但是你如何使用 .net core 来做到这一点?我在 package.json
中没有看到任何让我定义别名的选项,就像我在程序集引用属性窗口中所做的那样.
But how do you do that using .net core ?
I dont see any option in package.json
that would let me define an alias like I would do in an assembly reference property window.
我设法找到的唯一提到的这个问题是这里
The only mention of this issue i managed to find is here
推荐答案
我相信您尝试链接的问题在这里:
https://github.com/NuGet/Home/issues/4989
I believe the issue you are trying to link to is here:
https://github.com/NuGet/Home/issues/4989
您可以通过使用 MSBuild 目标来解决.将此代码段放入 Directory.Build.targets
:
You can workaround by using an MSBuild Target. drop this snippet into Directory.Build.targets
:
<Target Name="AddPackageAliases" BeforeTargets="ResolveReferences" Outputs="%(PackageReference.Identity)">
<PropertyGroup>
<AliasPackageReference>@(PackageReference->'%(Identity)')</AliasPackageReference>
<AliasName>@(PackageReference->'%(Alias)')</AliasName>
</PropertyGroup>
<ItemGroup>
<ReferencePath Condition="'%(FileName)'=='$(AliasPackageReference)'">
<Aliases>$(AliasName)</Aliases>
</ReferencePath>
</ItemGroup>
</Target>
然后在 PackageReference 节点的 csproj 中使用它,如下所示:
and then use it in your csproj in your PackageReference nodes like this:
<ItemGroup>
<PackageReference Include="StackExchange.Redis.StrongName" Version="1.2.6" Alias="signed" />
</ItemGroup>
将此添加为对 GitHub 问题的评论:
https://github.com/NuGet/Home/issues/4989#issuecomment-426666530
added this as a comment to the GitHub issue:
https://github.com/NuGet/Home/issues/4989#issuecomment-426666530
这篇关于如何使用 .Net 核心`extern alias` 程序集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!