XSharpPublic icon indicating copy to clipboard operation
XSharpPublic copied to clipboard

TargetFramework attribute is not automatically added to the assembly when building in VS

Open cpyrgas opened this issue 1 year ago • 5 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.

cpyrgas avatar Jul 03 '24 10:07 cpyrgas

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.*")]

cpyrgas avatar Jul 03 '24 10:07 cpyrgas

I have implemented this for the SDK style projects. Are you sure that C# also does this for the traditional project file format?

RobertvanderHulst avatar Jul 03 '24 15:07 RobertvanderHulst

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.

cpyrgas avatar Jul 04 '24 08:07 cpyrgas

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"....

RobertvanderHulst avatar Jul 04 '24 09:07 RobertvanderHulst

I do not see such an entry in the .csproj file. Btw, I created the test project with VS2019

cpyrgas avatar Jul 04 '24 16:07 cpyrgas

Confirmed fixed

cpyrgas avatar Sep 25 '24 09:09 cpyrgas