22
votes

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!

6

6 Answers

19
votes

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.

13
votes

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.

The [TargetFrameworkAttribute] it generates in the .cpp helper file is important, that tells the CLR on the machine on which the program runs what minimum version of .NET needs to be present to successfully execute the program. Its primary use is to automatically launch the installer for the .NET version that's needed, very nice feature.

LNK4221 is common and has no teeth, you can ignore it. Sadly the linker does not provide a documented way to suppress warnings, basic issue is that it cannot be specific enough to suppress only this one. Suppressing the helper .cpp would require editing the .targets file and breaks the auto-install feature, I cannot recommend that.

5
votes

I resolved this problem with the following steps:

  1. Clean the solution

  2. Close the solution

  3. Type in run command %temp%, delete all the files

  4. Open the solution by clicking the project solution file from the folder where the project has been saved.

  5. Do a rebuild on one of the projects. Then close Visual Studio 2010 (yes the entire development environment), and then re-open the solution file.

    It seems that the rebuild, recreates the missing file, but Visual Studio doesn't notice it, so you have to close it down and re-open it for it to properly see the file again.

2
votes

Firstly, @Brian's answer remedies the condition and I issued 4x+1s for the other helpful answers which assisted in a speedy diagnosis and resolution of an issue I experienced.

Wanted to include a dump of a problem I diagnosed in my context based on this.

This feature synthesizes a source file in the project's language which creates an assembly:attribute into the compilation stream.

This file/process is necessary when WAS or other hosting environments need to be able to infer a target framework and other such cases. Example MSDN article (relating to usage with WAS). It's only an attribute, so it's inert and not much to worry about...

In cases where no such reliance will come into play, it gets more interesting. Aside from being redundant, making larger binaries and heating the processor, in TeamCity, the cleaning procedures when configured for incremental builds remove this file before a re-build. However the unfortunate side effect is that the build's dependency checking then incorrectly infers that a rebuild is necessary as illustrated by this sample message when turning the logging up by specifying /v:d[etailed]:-

[CoreCompile] Input file "C:\BuildAgent\temp\buildTmp.NETFramework,Version=v4.0,Profile=Client.AssemblyAttributes.cs" is newer than output file "bin\Debug\DLLNAME.xml".

Bottom line is that CSC gets invoked inappropriately (and in our case there are significant downstream effects from there)

Other notes:

  • Must look in the MS Targets to see if this only applies to particlar Profiles [as alluded to in @AlainA's answer] (my specific case was a use of .NET 4.0 Client Profile)

  • As illustrated in the above message, one subtlety that may be involved is the presence or absence of XML docs, which is the case in my context.

1
votes

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

1
votes

Close VS

Open each .vbproj file with notepad and remove the following line : <TargetFrameworkProfile />

It's over !