Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 12830 multi target demo console #12996

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

ricardobossan
Copy link
Member

@ricardobossan ricardobossan commented Feb 21, 2025

Fixes #12830

Proposed changes

  • Updated DemoConsole.csproj and DesignSurfaceExt.csproj to support multiple target frameworks ($(NetCurrent)-windows;net481).
  • Adjusted TargetFramework property to avoid over-building.
  • Enabled SignAssembly and GenerateAssemblyInfo properties in the project files.
  • Updated resource and reference handling in DemoConsole.csproj and DesignSurfaceExt.csproj to improve compatibility.
  • Fixed Controls.AddRange usage to use the correct syntax in MainForm.MyUserControl.cs.
  • Corrected Controls.AddRange call in MainForm.cs to Controls.Add.
  • Suppressed IDE0057 warning and reverted to Substring method for compatibility in NameCreationServiceImp.cs.
  • Changed StartsWith('_') check by directly accessing the first character in NameCreationServiceImp.cs for compatibility.
  • Disabled error CA1824 for projects DemoConsole and DesignSurficeExt, because it would be triggered even though properly configured in those projects, according to the fix provided by the documentation.

Customer Impact

  • None

Regression?

  • No

Risk

  • Minimal

Screenshots

Before

  • DemoConsole would not run on net481.

After

image

Test methodology

  • Manual

Test environment(s)

  • 10.0.100-alpha.1.25077.2

@ricardobossan ricardobossan self-assigned this Feb 21, 2025
@ricardobossan
Copy link
Member Author

Drafted because:

  • Need to address nullability warnings
  • net481 compiles without errors but doesn't launch

@ricardobossan
Copy link
Member Author

ricardobossan commented Feb 21, 2025

@Tanya-Solyanik @LeafShi1 @Epica3055 I was able to get the DemoConsole project to compile for multiple targets ($(NetCurrent)-windows and net481), but it doesn't launch on net481. There's no error message explaining why. It just fails silently. Do you have any idea what might be causing this?

I’m aware of the nullability warnings that I still need to address, but could they be related to this issue?

@dotnet-policy-service dotnet-policy-service bot added the draft draft PR label Feb 21, 2025
Copy link
Member

@Tanya-Solyanik Tanya-Solyanik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Enable all CLR exceptions before starting to debug this project as 4.8.1. I guess immutable collection reference is not discovered.

<ItemGroup>
<EmbeddedResource Update="Properties\Resources.resx" Generator="ResXFileCodeGenerator" LastGenOutput="Resources.Designer.cs" />
<Compile Update="Properties\Resources.Designer.cs" AutoGen="True" DependentUpon="Resources.resx" DesignTime="True" />
<PackageReference Include="System.Resources.Extensions" VersionOverride="5.0.0"/>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why this is needed now, we were building resources for Core correctly before this change.

Copy link
Member Author

@ricardobossan ricardobossan Feb 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is necessary to avoid this build error when building from DemoConsole:

# On `DemoConsole` folder:
dotnet restore
msbuild /t:Clean DemoConsole.csproj
msbuild

output:

C:\Program Files\dotnet\sdk\10.0.100-preview.2.25117.4\Microsoft.Common.CurrentVersion.targets(3426,5): error MSB3822: Non-string resources require the System.Resources.Extensions assembly at runtime, but it was not found in this project's references.

However, this error doesn't show when building from the solution's root folder.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not hard code package versions, are we not getting this version automatically?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This package reference and version is set both in eng/Versions.props and in Directory.Packages.props. However, the build fails for net481:

System.Windows.Forms.PrivateSourceGenerators succeeded (6.5s) → artifacts\bin\System.Windows.Forms.PrivateSourceGenerators\Debug\netstandard2.0\System.Windows.Forms.PrivateSourceGenerators.dll
DemoConsole net481 failed with 1 error(s) (0.5s)

To remedy that, first I tried override the package specifically in DemoConsole.csproj.

I'll condition it to net481, since it's the only affected version.

@@ -37,6 +40,7 @@ protected override void Dispose(bool disposing)
base.Dispose(disposing);
}

[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change can be factored out into a separate PR with some other cleanup changes you have

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is necessary to prevent the following build error, which occurs regardless of whether the solution is built from the root or the DemoConsole folder:

"C:\Users\v-rbossan\source\repos\winforms\Winforms.sln" (default target) (1) ->
"C:\Users\v-rbossan\source\repos\winforms\src\System.Windows.Forms\tests\IntegrationTests\DesignSurface\DemoConsole\DemoConsole.csproj" (default target) (42) ->
"C:\Users\v-rbossan\source\repos\winforms\src\System.Windows.Forms\tests\IntegrationTests\DesignSurface\DemoConsole\DemoConsole.csproj" (Build target) (42:2) ->
"C:\Users\v-rbossan\source\repos\winforms\src\System.Windows.Forms\tests\IntegrationTests\DesignSurface\DesignSurfaceExt\DesignSurfaceExt.csproj" (default target) (43:4) ->
(CoreCompile target) ->
C:\Users\v-rbossan\source\repos\winforms\src\System.Windows.Forms\tests\IntegrationTests\DesignSurface\DesignSurfaceExt\PropertyGridExt.cs(43,26): error WFO1000: Property 'DesignerHost' does not configur
e the code serialization for its property content [C:\Users\v-rbossan\source\repos\winforms\src\System.Windows.Forms\tests\IntegrationTests\DesignSurface\DesignSurfaceExt\DesignSurfaceExt.csproj::TargetFra
mework=net10.0-windows]

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that this change is necessary, I suggest getting it in before the rest of the changes in this PR to make this PR more targetted.

Copy link
Member Author

@ricardobossan ricardobossan Feb 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed that change and this time was able to build without errors.

Should I still create a PR for it regardless?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ricardobossan -

Should I still create a PR for it regardless?

yes, please

@ricardobossan ricardobossan force-pushed the Issue_12830_Multi-Target_DemoConsole branch from e1471f3 to 78c0cbd Compare February 21, 2025 18:03
@Tanya-Solyanik
Copy link
Member

@ricardobossan - the reason the NET481 version does not run is that the dll is not strong-name signed, we should delay-sign it. Arcade should have tools for that. Maybe like this <SignAssembly>true</SignAssembly> https://github.com/dotnet/arcade/blob/ecdb2f499cb5f5c99b58fba1a14fdf977c56e1ac/Documentation/ArcadeSdk.md?plain=1#L953
Search arcade docs to see if they recommend any signing test keys to use. We should not use a production key.

…lizationVisibility annotatino from DesignerHost
Ricardo Bossan (BEYONDSOFT CONSULTING INC) added 2 commits February 24, 2025 16:07
…ystem.Collections.Immutable, in the DesignSurfaceExt project
Copy link

codecov bot commented Feb 24, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 76.09601%. Comparing base (f280449) to head (90f985f).
Report is 30 commits behind head on main.

Additional details and impacted files
@@                 Coverage Diff                 @@
##                main      #12996         +/-   ##
===================================================
+ Coverage   76.01028%   76.09601%   +0.08573%     
===================================================
  Files           3267        3272          +5     
  Lines         643459      643700        +241     
  Branches       47432       47438          +6     
===================================================
+ Hits          489095      489830        +735     
+ Misses        150791      150306        -485     
+ Partials        3573        3564          -9     
Flag Coverage Δ
Debug 76.09601% <ø> (+0.08573%) ⬆️
integration 18.03334% <ø> (+0.00509%) ⬆️
production 50.11043% <ø> (+0.15561%) ⬆️
test 96.95339% <ø> (+0.01655%) ⬆️
unit 47.54636% <ø> (+0.13369%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

@ricardobossan ricardobossan marked this pull request as ready for review February 24, 2025 20:00
@ricardobossan ricardobossan requested a review from a team as a code owner February 24, 2025 20:00
@ricardobossan ricardobossan added waiting-review This item is waiting on review by one or more members of team and removed draft draft PR labels Feb 24, 2025
@LeafShi1
Copy link
Member

When using only net481 in the DemoConsole project, TabPage6 does not display properly. When enabling all CLR exceptions before starting to debug this project, I receive the following error

image

@ricardobossan
Copy link
Member Author

@LeafShi1 I was able to run the project and navigate through the tabs on net481 with all CLR exceptions enabled, as shown in the GIF below:

clr exceptions enabled net481 works

Here’s how I set up and ran the project:

# From the runtime repo root folder:
gh pr checkout 12996
msbuild /t:Clean .\Winforms.sln
.\Restore.cmd
.\build.cmd
.\start-vs.cmd

Could you share the exact steps you're using to run the project? That might help pinpoint any differences that could explain the discrepancy in our results.

@LeafShi1
Copy link
Member

Could you share the exact steps you're using to run the project? That might help pinpoint any differences that could explain the discrepancy in our results.

When using <TargetFrameworks>$(NetCurrent)-windows;net481</TargetFrameworks>, it shows up fine on my end。
I just tried changing the TargetFramework to net481, like this
image

But it doesn't seem to work, because it causes compilation to fail

So please ignore my comment

<ImplicitUsings>enable</ImplicitUsings>
<SignAssembly>true</SignAssembly>
Copy link
Member

@Tanya-Solyanik Tanya-Solyanik Feb 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need this property on .NET Core, we should include it conditionally.
Language version is already set to latest for Core.


<!-- Do not build this project when doing a .NET product build. -->
<!-- The files for this project have been removed from the .NET product due to licensing issues. -->
<ExcludeFromDotNetBuild>true</ExcludeFromDotNetBuild>
<IsTestUtilityProject>true</IsTestUtilityProject>
<TargetFrameworks>$(NetCurrent)-windows;net481</TargetFrameworks>
Copy link
Member

@Tanya-Solyanik Tanya-Solyanik Feb 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most new and some old properties are shared between DemoConsole and the DesignSurfaceExt projects, you can factor them out into Directory.Build.props file in the DesignSurface folder. It will be easier to update them in a single place in the future.


<ItemGroup Condition="'$(TargetFramework)' == '$(NetCurrent)-windows'">
<ProjectReference Include="..\..\..\..\..\System.Design\src\System.Design.Facade.csproj" />
<ProjectReference Include="..\..\..\..\..\System.Drawing.Design\src\System.Drawing.Design.Facade.csproj" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think facade assemblies are required here as we reference them in the DesignSurfaceExt.csproj

@@ -32,7 +33,9 @@ public string CreateName(IContainer container, Type type)
count++;
try
{
int value = int.Parse(name[type.Name.Length..]);
#pragma warning disable IDE0057
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add the comment that describes this rule (the one that the codefix adds) to line 36. And also mention that the reason we suppress it is that the Range is not available on .NET Framework. Alternatively, you can use Range when compiling for Core only, i.e. use #if NETCOREAPP

<ItemGroup>
<EmbeddedResource Update="Properties\Resources.resx" Generator="ResXFileCodeGenerator" LastGenOutput="Resources.Designer.cs" />
<Compile Update="Properties\Resources.Designer.cs" AutoGen="True" DependentUpon="Resources.resx" DesignTime="True" />
<PackageReference Include="System.Resources.Extensions" VersionOverride="5.0.0"/>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not hard code package versions, are we not getting this version automatically?

@Tanya-Solyanik Tanya-Solyanik added waiting-author-feedback The team requires more information from the author and removed waiting-review This item is waiting on review by one or more members of team labels Feb 26, 2025
<Copyright>Copyright © Paolo Foti 2008</Copyright>
<Company />
<Authors>Paolo Foti</Authors>
<PackageLicenseExpression>CPOL</PackageLicenseExpression>
<PackageProjectUrl>https://www.codeproject.com/Articles/24385/Have-a-Great-DesignTime-Experience-with-a-Powerful</PackageProjectUrl>
<SuppressLicenseValidation>true</SuppressLicenseValidation>
<EnableUnsafeBinaryFormatterSerialization>true</EnableUnsafeBinaryFormatterSerialization>
<GenerateResourceUsePreserializedResources>true</GenerateResourceUsePreserializedResources>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this one is needed for the .NET Framework case only

<ProjectReference Include="..\..\..\..\..\System.Design\src\System.Design.Facade.csproj" />
<ProjectReference Include="..\..\..\..\..\System.Drawing.Design\src\System.Drawing.Design.Facade.csproj" />
<ProjectReference Include="..\..\..\..\..\System.Windows.Forms.Design\src\System.Windows.Forms.Design.csproj" />
<ProjectReference Include="..\..\..\..\src\System.Windows.Forms.csproj" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net481'">
<PackageReference Include="System.Collections.Immutable" VersionOverride="9.0.2" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to move this version to versions.props?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting-author-feedback The team requires more information from the author
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make the DemoConsole application multi-targeted to both .NET and .NET Framework
3 participants