如何使用.Net核心“外部别名”装配体? [英] 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进行分类,这很容易。只需使用 外部别名 。
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
似乎有一个未解决的问题此处
[edit] It seems that there is an open issue 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 Target来解决。将此代码段放入 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核心“外部别名”装配体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!