views:

373

answers:

3

I've recently upgraded to Visual Studio 2010. Now when I build projects I get a line that reads:

1>  .NETFramework,Version=v4.0.AssemblyAttributes.cpp

I've learned that this is the result of the new build engine, msbuild.exe, but this file is actually auto-created and placed in my local temp directory (c:\Documents and Settings\me\Local Settings\Temp). Does anyone know why this file is created, and whether I can disable its creation?

BTW, it doesn't seem to have anything useful in it, to my mind. See below:

#using <mscorlib.dll>
[assembly: System::Runtime::Versioning::TargetFrameworkAttribute(L".NETFramework,Version=v4.0", FrameworkDisplayName=L".NET Framework 4")];

And occasionally, as reported http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/15d65667-ac47-4234-9285-32a2cb397e32, it causes problems. So any information on this file, and how I can avoid its auto-creation would be much appreciated. Thank you!

+3  A: 

Take a look at c:\program files\msbuild\microsoft.cpp\v4.0\microsoft.buildsteps.targets. It contains the GenerateTargetFrameworkMonikerAttribute target, that's the one that generates the file. The Condition element determines when it runs, GenerateTargetFrameworkAttribute is the value. That will always be true if the project settings ask for a /clr build. The comment in the target is very misleading, the hoopla about precompiled header files has nothing to do with the purpose of the target.

Guessing why the TargetFrameworkAttribute is needed is harder, the MSDN Library article for it gives no hint. I think it is required because, unlike the C# and VB.NET languages, it is technically possible in C++/CLI to link .obj and .lib files that were compiled with different settings for the target framework version. That would be bad.

If this guess is accurate then it would have to be the linker that enforces this attribute value and you should get some kind of linker error or warning when you try to mix and match.

LNK4221 is common and has no teeth, you can ignore it. Suppressing the helper .cpp would require editing the .targets file, I would not recommend that.

Hans Passant
Thank you very much for all that information! Is there somewhere that I could read up more about msbuild and these XML files it uses that is perhaps clearer than http://msdn.microsoft.com/en-us/library/0k6kkbsd.aspx? I couldn't even find the GenerateTargetFrameworkMonikerAttribute target in the MSDN documentation. As for the warning, my company has a policy that builds must be warning free, as they often point to code stink.
Michael Repucci
No, these are implementation details, not unlike the internals of link.exe. They just happen to be readable, not a bad thing. Getting link.exe completely warning-free is difficult, you cannot suppress warnings. Nor can you fail the build with them so few programmers care. Maybe VS2010 is not quite ready for prime time at your company. Post to connect.microsoft.com to ask for feature changes.
Hans Passant
A: 

This is common to all languages (C#, VB, and F# have something similar too).

One way you can disable it is to override the GenerateTargetFrameworkMonikerAttribute target thusly:

<!-- somewhere after the Import of Microsoft.somelanguage.targets -->
<Target Name="GenerateTargetFrameworkMonikerAttribute" />

in your project file.

Brian
I edited the vcxproj file by hand and added that line, as you suggested, and it worked. But is there a setting or place to add that in the project property pages? And even more importantly, is it safe? What am I losing?
Michael Repucci
See here for what the TargetFrameworkAttribute feature supports: http://msdn.microsoft.com/en-us/library/dd456789.aspx
Brian
Interesting. Since the project doesn't contain any WCF, IIS, or Web anything, I guess it'd be safe to override as you suggested. But I'm rather surprised that this ever came up. Any ideas why it might have arisen?
Michael Repucci
I agree it's safe to omit. I know nothing about the C++ linker, so I've no clue about the warning.
Brian
A: 

The file is there to embed TargetFrameworkMoniker .NET assembly attribute. That is to (in future) help hosts work correctly with the appropriate CLR. (Sorry for vagueness I can't remember someone else is the expert). Ie', there's actually a reason for it :-)

I don't know why there's a warning -- looking into it.

Dan/MSBuild

dan