Skip to content

Modernize workloads and templates#462

Open
mattleibow wants to merge 5 commits intoGtkSharp:developfrom
mattleibow:dev/mattleibow/workloads
Open

Modernize workloads and templates#462
mattleibow wants to merge 5 commits intoGtkSharp:developfrom
mattleibow:dev/mattleibow/workloads

Conversation

@mattleibow
Copy link
Copy Markdown

@mattleibow mattleibow commented Oct 6, 2025

Non-AI

Note

This PR is somewhat big and I never asked the community how they liked anything, but I was playing around for some local testing and decided to push along with some other changes. Feel free to close if this is not what you want. If any chnages are needed, let me know. If you want just parts of this, I can do smaller PRs.

I saw the workloads were using what was originally touted as the gold standard - SDK, runtime and refs in the workload. However, this is not always great as new versions will require workload things.

While working on .NET MAUI, we decided to go with a less workload-y way and just have a base x.0.100 workload installed once to add the required thigs (in the case of GtkSharp, it is the gtk target platform). After that, all the user needs is to update the version of the NuGet.

With the GtkSharp.Sdk package, I added and split the contents across the specific files ot make future things easier:

  • Sdk.props - root props that does nothing now but makes some loaders not throw when there is a missing Sdk.*
  • Sdk.targets - root targets for all the things
  • BundledVersions.in.targets - this is the file that has all the versions from the workload
  • GtkSharp.Sdk.targets - this file brings in the other targets and sets the <UsingGtkSharpSdk> property
  • GtkSharp.Sdk.Before.targets - this is the "normal" targets that run after the project file but BEFORE the .NET targets
  • GtkSharp.Sdk.After.targets - this is the targets file that runs AFTER the .NET targets

For the templates, I went out on a crazy limb and made there be a single template file that is controlled by a $(WorkloadBuild) to control the contents. Hopefully this makes edits in future nicer as there is no need to keep things in sync.

I also update the project templates to support the --framework and --no-restore like the rest of .NET.

AI

This pull request introduces a new PowerShell script for installing the GTK workload, refactors and enhances template configuration for workload support, and improves code style and template metadata across several files. The changes are mainly grouped into three themes: workload installation automation, template system enhancements, and code style/metadata improvements.

Workload installation automation:

  • Added a new script Scripts/workload-install.ps1 to automate the installation of the GTK workload for .NET SDKs, including manifest handling, version detection, and pack installation. This script supports custom sources and auto-detection of installation directories.

Template system enhancements:

  • Introduced a custom MSBuild task BulkReplaceText in Source/Directory.Build.targets to enable bulk text replacements in template files, and a build target to apply these replacements before build.
  • Updated Source/Templates/Directory.Build.props and template .csproj files to support a WorkloadBuild parameter, allowing conditional packaging and workload-specific template variants. [1] [2]
  • Added a new input template config template.in.json and host config dotnetcli.host.json for GTK application templates, supporting workload parameterization and improved symbol definitions. [1] [2]
  • Updated GtkNamespace.csproj to use workload-specific target frameworks and package references based on the UseWorkload parameter. [1] [2]

Code style and metadata improvements:

  • Refactored application, dialog, and widget template code files to use file-scoped namespaces and modern C# conventions, improving readability and consistency. [1] [2] [3] [4] [5] [6] [7] [8]
  • Updated template metadata files (template.json) for dialog, widget, and window templates to use improved default names, aiding discoverability and consistency. [1] [2] [3]
  • Removed the old static template.json for the GTK application template in favor of the new parameterized system.

Copy link
Copy Markdown
Author

@mattleibow mattleibow left a comment

Choose a reason for hiding this comment

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

Some comments to point out some changes

@@ -0,0 +1,253 @@
#!/usr/bin/env pwsh
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

This script sort of works on macOS. I did not test Linux. It won't work on Windows as that requires either MSI files (I may look at this in the future) or manually copying of things.

@@ -0,0 +1,15 @@
{
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

The cli files make the dotnet new gtk --help output look nicer with the lowercase flags:

% dotnet new gtkapp --help
Gtk Application (C#)
Author: GtkSharp Contributors

Usage:
  dotnet new gtkapp [options] [template options]

Options:
  -n, --name <name>       The name for the output being created. If no name is specified, the name of the output directory is used.
  -o, --output <output>   Location to place the generated output.
  --dry-run               Displays a summary of what would happen if the given command line were run if it would result in a template creation. [default: False]
  --force                 Forces content to be generated even if it would change existing files. [default: False]
  --no-update-check       Disables checking for the template package updates when instantiating a template. [default: False]
  --project <project>     The project that should be used for context evaluation.
  -lang, --language <C#>  Specifies the template language to instantiate.
  --type <project>        Specifies the template type to instantiate.

Template options:
  -f, --framework <net10.0|net8.0|net9.0>  The target framework for the project.
                                           Type: choice
                                             net8.0   Target net8.0
                                             net9.0   Target net9.0
                                             net10.0  Target net10.0
                                           Default: net8.0
  --no-restore                             If specified, skips the automatic restore of the project on create.
                                           Type: bool
                                           Default: false

To see help for other template languages (F#, VB), use --language option:
   dotnet new gtkapp -h --language F#

}
],
"replaces": "$(FrameworkParameter)",
"defaultValue": "net8.0"
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I kept .NET 8 as the default.

Comment on lines +19 to +20
<PackageReference Condition="'$(UseWorkload)' != 'true'" Include="GtkSharp" Version="3.24.24.*" />
<PackageReference Condition="'$(UseWorkload)' == 'true'" Include="GtkSharp" Version="$(GtkSharpVersion)" />
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

The new workload in this PR will not provide the references, you will need the NuGets. But now they can be updated from a nightly or just bumped independent of the workload version.

@lytico
Copy link
Copy Markdown
Member

lytico commented Oct 24, 2025

see #464

@lytico
Copy link
Copy Markdown
Member

lytico commented Oct 24, 2025

second problem:
your commits contains a lot of whitespace or formatting changes.
so it would be nice to split that into a whitespace or formatting commit
and then the "real" changes

@lytico
Copy link
Copy Markdown
Member

lytico commented Oct 24, 2025

but: ...
on a first review, it's very promising!
Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants