简体   繁体   中英

Microsoft.Bcl package using CallerMemberName fails to build within Teamcity

I have taken over a project that is targeting .net4.

One of the projects within the solution is using System.Runtime.CompilerServices.CallerMemberNameAttribute from the System.Runtime.dll that is installed when you are using the Microsoft BCL Portability Pack.

I have checked and the project is currently using version 1.1.3.

When the solution is build on local dev machines, everything compliles with no problems.

I am now trying to get the solution built in teamcity, but when TeamCity attempts to compile the solution I am getting this error. error CS0246: The type or namespace name 'CallerMemberName' could not be found (are you missing a using directive or an assembly reference?) error CS0433: The type 'System.Runtime.CompilerServices.CallerMemberNameAttribute' exists in both 'c:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\mscorlib.dll' and 'c:\\apps\\teamcity\\buildAgent\\work\\bb8aacaa9fabeac8\\packages\\Microsoft.Bcl.1.1.3\\lib\\net40\\System.Runtime.dll'

I have read Jon Skeets answer to this question: Using CallerMemberName attribute in a portable library But I am already using the BCL library.

After spending some time on this, I found another question answered by Jon Skeet that resolved this issue. When must we use extern alias keyword in C#?

Within my project, after getting the links to the Package, for each dll I had to change the name of the alias. ie from global to newglobal

Then in the classes that where using the CallerMemberName, had to do the following At the top of the page, above the using statements

extern alias newglobal;

And then when referencing CallerMemberName, enter the code as

[newglobal::System.Runtime.CompilerServices.CallerMemberName]

This allows the code to be successfully built on teamcity where .net 4.5 has been installed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM