7

Why does Visual Studio generates the following file .NETFramework,Version=v4.5.AssemblyAttributes.cs in the temp folder C:\Users\[USERNAME]\AppData\Local\Temp of the current user when building a solution?

The content of the file looks like that:

// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETFramework,Version=v4.5", FrameworkDisplayName = ".NET Framework 4.5")]

This question came into my mind because I've a problem when restarting my PC that this file is missing, see Visual Studio Rebuilds unmodified projects sometimes after a PC reboot.

Wollmich
  • 1,616
  • 1
  • 18
  • 46

1 Answers1

9

Why does Visual Studio generates the following file .NETFramework,Version=v4.5.AssemblyAttributes.cs in the temp folder

Since you are interested in the reasons for generating this file, I suggest that you can check this document:

MSBuild: unnecessary rebuilds because of generated AssemblyAttributes.cs

Kirill Osenkov used an example in that article to explain why the file was generated in the temp folder.

Similarly, we could to know the reason for those unnecessary rebuilds after this file generated in that article and how to resolve this issue.

So add the following lines to your csproj file:

  <PropertyGroup>
    <TargetFrameworkMonikerAssemblyAttributesPath>$([System.IO.Path]::Combine('$(IntermediateOutputPath)','$(TargetFrameworkMoniker).AssemblyAttributes$(DefaultLanguageSourceExtension)'))</TargetFrameworkMonikerAssemblyAttributesPath>
  </PropertyGroup>

Hope this helps.

Wollmich
  • 1,616
  • 1
  • 18
  • 46
Leo Liu
  • 71,098
  • 10
  • 114
  • 135
  • If I add this to my file, then later, change the .csproj file to target a new version of the .net framework, the .AssemblyAttributes file DOES NOT get re-generated. I have to do a Rebuild or delete the .AssemblyAttributes file. – Ike Starnes Oct 02 '20 at 18:00