X-Sharp / XSharpPublic

Public repository for the source code for the XSharp Compiler, Runtime, Project System and Tools.
Apache License 2.0
89 stars 36 forks source link

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

Open cpyrgas opened 5 days ago

cpyrgas commented 5 days ago

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 commented 5 days ago

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

RobertvanderHulst commented 5 days ago

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

cpyrgas commented 4 days ago

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.

RobertvanderHulst commented 4 days ago

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

cpyrgas commented 4 days ago

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