开发者

How to create an extern alias for System.Core?

开发者 https://www.devze.com 2022-12-27 12:38 出处:网络
I absolutely need an extern alias for System.Core in my project. Unfortunately, in a .开发者_如何学CNet 4.0 project, you cannot even add a reference to System.Core because, apparently, the build syste

I absolutely need an extern alias for System.Core in my project. Unfortunately, in a .开发者_如何学CNet 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!


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....
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号