Skip to content

feat: Make Directory.Build files conditional on package requirements#1872

Merged
jeromelaban merged 5 commits into
mainfrom
copilot/enhance-default-presets-visual-studio
Nov 27, 2025
Merged

feat: Make Directory.Build files conditional on package requirements#1872
jeromelaban merged 5 commits into
mainfrom
copilot/enhance-default-presets-visual-studio

Conversation

Copilot AI commented Nov 26, 2025

Copy link
Copy Markdown
Contributor
  • Explore repository structure and understand the template system
  • Identify Directory.Build.* files and their content
  • Understand when packages are required
  • Create computed symbol to determine if Directory.Build/Packages files are needed
  • Move Directory.Build.props content to main csproj when no packages needed
  • Make Directory.Build.* files conditional on requiring packages
  • Keep CPM (ManagePackageVersionsCentrally) in Directory.Build.props when generated
  • Test changes with blank and recommended presets
  • Verify changes don't break existing configurations that need Directory.Build files
  • Address reviewer feedback on CPM
  • Add parameters for Uno.SDK version control and global.json generation
  • Refine NoWarn suppressions based on configuration

Summary

This implementation makes the unoapp template's blank and recommended presets self-contained by:

  1. Conditionally generating Directory.Build files - Only created when NuGet packages are required (tests, server, MAUI, developer mode, or WASM packages)

  2. Embedding properties in main csproj - When no packages are needed, ImplicitUsings, Nullable, and NoWarn are added directly to the project file

  3. Preserving CPM when needed - ManagePackageVersionsCentrally remains in Directory.Build.props when the file is generated, ensuring proper package version management with Directory.Packages.props

  4. SDK version control - Added --uno-sdk-version parameter to allow customizing the Uno.SDK version in global.json

  5. Optional global.json - Added --include-global-json parameter (default: true) to optionally exclude global.json generation for projects that manage SDK versions externally

  6. Refined warning suppressions - NoWarn settings are now configuration-specific:

    • NU1507: Only when CPM is enabled (requiresNugetPackages)
    • NETSDK1201, PRI257: Only when WinAppSDK platform is selected
    • NETSDK1023: Only when MAUI embedding is enabled

This allows template-generated projects to be easily added to existing solutions without Directory.Build file conflicts in simple scenarios, while maintaining proper CPM when packages are required and allowing flexible SDK management.

Original prompt

This section details on the original issue you should resolve

<issue_title>Enhance the default presets to be self contained in Visual Studio</issue_title>
<issue_description>The unoapp template's blank and recommended presets require the use of Directory.Build.*, which make them difficult to include in existing projects.

These files are needed in some of the scenarios, such as when explicit packages are added such as the server project or test projects.

The enhancement should have the template not generate the Directory.Build.* files when no nuget packages are required by the configuration switches, and move the original content from the Directory.Build.* into the csproj. It should also not include the CPM feature, which would make it inherit from the current solution's configuration, if any.</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Related to: https://github.com/unoplatform/uno-private/issues/1618

- Add requiresNugetPackages computed symbol to determine if packages are needed
- Exclude Directory.Build.*, Directory.Packages.props when no packages required
- Move ImplicitUsings, Nullable, NoWarn to main csproj when no packages
- Remove ManagePackageVersionsCentrally from Directory.Build.props to avoid CPM conflicts
- Tested with blank, recommended, tests, maui-embedding, and server configurations

Co-authored-by: jeromelaban <5839577+jeromelaban@users.noreply.github.com>
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

1 similar comment
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copilot AI changed the title [WIP] Enhance default presets to be self-contained in Visual Studio feat: Make Directory.Build files conditional on package requirements Nov 26, 2025
Copilot AI requested a review from jeromelaban November 26, 2025 14:04
@jeromelaban

Copy link
Copy Markdown
Member

@copilot src/Uno.Templates/content/unoapp/Directory.Build.props:5 This seems incorrect. The CPM should be kept in this file, since we want CPM enabled when packages are referenced by the template's parameters.

CPM should be enabled when Directory.Build.props is generated (i.e., when packages are required). The file is only generated when needed, so CPM won't conflict with parent solutions.

Co-authored-by: jeromelaban <5839577+jeromelaban@users.noreply.github.com>

Copilot AI commented Nov 26, 2025

Copy link
Copy Markdown
Contributor Author

@copilot src/Uno.Templates/content/unoapp/Directory.Build.props:5 This seems incorrect. The CPM should be kept in this file, since we want CPM enabled when packages are referenced by the template's pa...

You're correct! I've restored the ManagePackageVersionsCentrally property. The CPM should be enabled when Directory.Build.props is generated (when packages are required), and since the file is conditionally generated, it won't conflict with parent solution configurations when not needed.

Fixed in commit f17f65a.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • aka.ms
    • Triggering command: /usr/bin/dotnet dotnet pack src/Uno.Templates/Uno.Templates.csproj -c Release (dns block)
    • Triggering command: /usr/bin/dotnet dotnet pack src/Uno.Templates/Uno.Templates.csproj -c Release --no-restore (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

@jeromelaban

Copy link
Copy Markdown
Member

@copilot Let's also add two additional parameters. One for allowing to change the uno.sdk version in global.json, and another one to not generate the global.json file.

- Add displayName and description to unoSdkVersion parameter for better discoverability
- Add includeGlobalJson parameter to optionally exclude global.json generation
- Useful when integrating into existing solutions with their own SDK management

Co-authored-by: jeromelaban <5839577+jeromelaban@users.noreply.github.com>

Copilot AI commented Nov 26, 2025

Copy link
Copy Markdown
Contributor Author

@copilot Let's also add two additional parameters. One for allowing to change the uno.sdk version in global.json, and another one to not generate the global.json file.

Added both parameters in commit 3882eac:

  1. --uno-sdk-version - Enhanced existing parameter with displayName and description to allow customizing the Uno.SDK version in global.json (defaults to template version)

  2. --include-global-json - New parameter (default: true) to optionally exclude global.json generation when set to false, useful for projects managing SDK versions externally

Example usage:

dotnet new unoapp -n MyApp --uno-sdk-version 5.2.0
dotnet new unoapp -n MyApp --include-global-json false

@jeromelaban

Copy link
Copy Markdown
Member

@copilot src/Uno.Templates/content/unoapp/.template.config/template.json:812 I'm not seeing a change in global.json that uses that parameter.

Copilot AI commented Nov 26, 2025

Copy link
Copy Markdown
Contributor Author

@copilot src/Uno.Templates/content/unoapp/.template.config/template.json:812 I'm not seeing a change in global.json that uses that parameter.

The unoSdkVersion parameter was already functional before my changes - global.json uses $UnoSdkVersion$ on line 4, which gets replaced by the parameter via the replaces property.

In commit 3882eac, I only added displayName and description to make the existing parameter more discoverable when users run dotnet new unoapp --help. The parameter itself and its usage in global.json were already working.

Users can already use: dotnet new unoapp --uno-sdk-version 5.2.0 to customize the SDK version.

@jeromelaban

Copy link
Copy Markdown
Member

@copilot When runing without CPM (Uno.Templates/content/unoapp/.template.config/template.json:816) NU1507 is not needed.

For NETSDK1201;PRI257, let's only add them (and the associated comment) when winappsdk is selected in the platforms.

…itional on WinAppSDK

- NU1507 is CPM-specific, so removed when !requiresNugetPackages (no CPM)
- NETSDK1201 and PRI257 are WinAppSDK-specific, now only added when useWinAppSdk is true
- NETSDK1023 remains MAUI-specific and only added when mauiEmbedding is true
- Updated both Directory.Build.props and main csproj consistently

Co-authored-by: jeromelaban <5839577+jeromelaban@users.noreply.github.com>

Copilot AI commented Nov 26, 2025

Copy link
Copy Markdown
Contributor Author

@copilot When runing without CPM (Uno.Templates/content/unoapp/.template.config/template.json:816) NU1507 is not needed.

For NETSDK1201;PRI257, let's only add them (and the associated comment) when ...

Fixed in commit 4c13476:

  1. NU1507 - Removed from csproj when !requiresNugetPackages (no CPM). It remains in Directory.Build.props where CPM is enabled.

  2. NETSDK1201 and PRI257 - Now conditional on useWinAppSdk in both files, only added when Windows platform is selected.

  3. NETSDK1023 - Remains MAUI-specific, only added when mauiEmbedding is true.

Each warning suppression is now applied only when the relevant feature is enabled.

@jeromelaban
jeromelaban marked this pull request as ready for review November 27, 2025 12:59
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.

Enhance the default presets to be self contained in Visual Studio

4 participants