How to create an extern alias for System.Core?

柔情痞子 提交于 2019-12-12 09:45:33

问题


I absolutely need an extern alias for System.Core in my project. Unfortunately, in a .Net 4.0 project, you cannot even add a reference to System.Core because, apparently, the build system includes it by default. Does anyone have any idea on how I can coerce the system to let me specify an extern alias for this lib? Thanks!


回答1:


This question is old but I ran into the same problem. As far as I understood, this is due to Visual Studio implicitly adding a reference to System.Core.

You can override this by editing your csproj msbuild file and adding:

<PropertyGroup>
   <AdditionalExplicitAssemblyReferences/>
</PropertyGroup>

at the end.

This disables any AdditionalExplicitAssemblyReferences that I assume Visual Studio has passed to MSBuild using the /p[roperty] switch. Of course, we now still have to add the System.Core reference as it is no longer referenced. Do so by adding

<Reference Include="System.Core">
   <RequiredTargetFramework>3.5</RequiredTargetFramework>
   <Aliases>global,ActualSystemCore</Aliases>
</Reference>

to the ItemGroup that contains references (or a new one).

You can now refer to a System.Core type using

ActualSystemCore::System....


来源:https://stackoverflow.com/questions/2643412/how-to-create-an-extern-alias-for-system-core

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!