TargetFramework attribute is not automatically added to the assembly when building in VS
Closed this issue · 6 comments
For c#, VS generates an extra .xs file with a name like "\obj\Debug.NETFramework,Version=v4.8.1.AssemblyAttributes.cs" which contains a TargetFramework attribute, based on the target framework selected in the project settings. Contents of this file:
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETFramework,Version=v4.8.1", FrameworkDisplayName = ".NET Framework 4.8.1")]
This attribute is necessary for supporting some advanced features in winforms.
In X#, this attribute is not inserted automatically, as a workaround it must be inserted manually in the code.
Somewhat related, c# includes in AssemblyInfo.cs those attributes (among many others of course):
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
The X# templates only include this
[assembly: AssemblyVersion("1.0.*")]
I have implemented this for the SDK style projects. Are you sure that C# also does this for the traditional project file format?
Not sure what an SDK style project is, but I created a simple c# Console Project, targetted 4.8.1 and it did add the extra file with the attribute.
SDK style project files have this code
<Project Sdk="Microsoft.NET.Sdk">
Old style projects do not have the SDK attribute
<Project ToolsVersion="4.0"....
I do not see such an entry in the .csproj file. Btw, I created the test project with VS2019
Confirmed fixed