From 7353f8e7fff954b924e5998c314e519701e65ef6 Mon Sep 17 00:00:00 2001 From: Jerome Laban Date: Tue, 31 Jan 2023 13:47:45 -0500 Subject: [PATCH 1/3] docs: Add an article to enable faster single-targetframework builds in VS 2022 (cherry picked from commit 66af3e0f209b3d348431ebe685bc517dd02d9c67) --- ...olution-building-single-targetframework.md | 83 +++++++++++++++++++ doc/articles/toc.yml | 2 + doc/articles/uno-app-solution-structure.md | 2 + 3 files changed, 87 insertions(+) create mode 100644 doc/articles/guides/solution-building-single-targetframework.md diff --git a/doc/articles/guides/solution-building-single-targetframework.md b/doc/articles/guides/solution-building-single-targetframework.md new file mode 100644 index 000000000000..e237426202eb --- /dev/null +++ b/doc/articles/guides/solution-building-single-targetframework.md @@ -0,0 +1,83 @@ +--- +uid: Build.Solution.TargetFramework-override +--- +# Adjust an Uno Solution for a faster build with Visual Studio 2022 + +The Uno Platform template provides a cross-targeted Class library which includes multiple target frameworks. While building with the command line `dotnet build -f net7.0-ios` does only build the application's head and the class library for `net7.0-ios`, Visual Studio builds all the target frameworks, [regardless of the project head's target framework](https://developercommunity.visualstudio.com/t/Building-a-cross-targeted-project-with-m/651372). + +Considering that during development, it is common to work on a single platform at a given time, here's a suggested set of modification that can be performed on the solution to restrict the active build platform: + +1. Let's create a set of solution filters to ensure that individual project heads can be loaded: + + 1. Create a new app template with **iOS**, **Android**, **WebAssembly** and **Windows** targets selected. + 1. Right click on the **.Mobile** and **.Wasm** projects and select **Unload Project** + 1. On the top level Solution node, right click to select **Save As Solution Filter**, name the filter **MyApp-Windows-Only.slnf** + + 1. Right click on the **Mobile** project, select **Reload Project** + 1. Unload the **.Windows** project, then save a new solution filter called **MyApp-Mobile- Only.slnf** + 1. Repeat the operation with the **.Wasm** project, with a solution filter called **MyApp-Wasm-Only.slnf** + + These solution filters will prevent Visual Studio to restore NuGet packages for TargetFrameworks that will be ignored by the configuration done below. + +1. Now next to the solution file, create a file named `targetframework-override.props`: + + ```xml + + + + + + $(MyAppTargetFrameworkOverride) + + + ``` +1. Also next to the solution file, create a file named `solution-config.props.sample`: + + ```xml + + + + + + + ``` +1. Next, in all projects of the solution which are cross-targeted (with multiple TargetFrameworks values), add the following lines right after the `PropertyGroup` which defines ``: + + ```xml + + + ``` + The file should then look like this: + ```xml + + + net7.0-windows10.0.18362;net7.0;net7.0-ios;net7.0-android + + + + + ``` + > [!NOTE] + > If the template is created with `dotnet new`, the path will instead be `../targetframework-override.props` +1. Create a copy of the file `solution-config.props.sample` next to itself, and name it `solution-config.props` +1. If using git, add this specific file to the `.gitignore` so it never gets committed. This way, each developer can keep their own version of the file without corrupting the repository. +1. Commit your changes to the repository. + +At this point, your solution is ready for single-TargetFramework use. + +For example, to work on `net7.0-ios`: +1. Before opening the solution, open the `solution-config.props` file and uncomment `MyAppTargetFrameworkOverride` to contain `net7.0-ios` +1. Open the `MyApp-Mobile-Only.slnf` solution filter in Visual Studio 2022 +1. You should only see the **.Mobile** and **Class Library** projects in your solution +1. When building and debugging the app, you'll only now build for the target specified in `solution-config.props`. + +> [!IMPORTANT] +> When changing the `MyAppTargetFrameworkOverride` value, make sure to close the solution and reload it so the build system recognizes properly the change. diff --git a/doc/articles/toc.yml b/doc/articles/toc.yml index ab8388aae04b..91065a1fb878 100644 --- a/doc/articles/toc.yml +++ b/doc/articles/toc.yml @@ -394,6 +394,8 @@ href: wpf-migration.md - name: Creating a cross-targeted library href: cross-targeted-libraries.md + - name: Faster Single Target App Builds + href: solution-building-single-targetframework.md - name: Hosting a WebAssembly app href: how-to-host-a-webassembly-app.md - name: Updating to WinUI 3.0 diff --git a/doc/articles/uno-app-solution-structure.md b/doc/articles/uno-app-solution-structure.md index 703368a29a8c..6330d13f1604 100644 --- a/doc/articles/uno-app-solution-structure.md +++ b/doc/articles/uno-app-solution-structure.md @@ -19,3 +19,5 @@ Dependencies in Uno solutions can be added preferably in the app's **Class Libra ## Further information See additional guides on handling platform-specific [C# code](platform-specific-csharp.md) and [XAML markup](platform-specific-xaml.md) in an Uno Platform project. + +The Uno Platform solution also [can be further optimized](xref:Build.Solution.TargetFramework-override) to build larger projects with Visual Studio 2022. From f49830e915a585ab84479d1b60d15a1d4a79a2cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Laban?= Date: Tue, 31 Jan 2023 14:17:00 -0500 Subject: [PATCH 2/3] docs: Apply suggestions from code review Co-authored-by: Youssef Victor (cherry picked from commit e61f44763672cc54e82c5bfe64810da849041a9b) --- .../guides/solution-building-single-targetframework.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/doc/articles/guides/solution-building-single-targetframework.md b/doc/articles/guides/solution-building-single-targetframework.md index e237426202eb..ea2107e51a30 100644 --- a/doc/articles/guides/solution-building-single-targetframework.md +++ b/doc/articles/guides/solution-building-single-targetframework.md @@ -12,14 +12,13 @@ Considering that during development, it is common to work on a single platform a 1. Create a new app template with **iOS**, **Android**, **WebAssembly** and **Windows** targets selected. 1. Right click on the **.Mobile** and **.Wasm** projects and select **Unload Project** 1. On the top level Solution node, right click to select **Save As Solution Filter**, name the filter **MyApp-Windows-Only.slnf** - 1. Right click on the **Mobile** project, select **Reload Project** 1. Unload the **.Windows** project, then save a new solution filter called **MyApp-Mobile- Only.slnf** 1. Repeat the operation with the **.Wasm** project, with a solution filter called **MyApp-Wasm-Only.slnf** These solution filters will prevent Visual Studio to restore NuGet packages for TargetFrameworks that will be ignored by the configuration done below. -1. Now next to the solution file, create a file named `targetframework-override.props`: +1. Now, next to the solution file, create a file named `targetframework-override.props`: ```xml @@ -31,6 +30,7 @@ Considering that during development, it is common to work on a single platform a ``` + 1. Also next to the solution file, create a file named `solution-config.props.sample`: ```xml @@ -49,13 +49,16 @@ Considering that during development, it is common to work on a single platform a ``` + 1. Next, in all projects of the solution which are cross-targeted (with multiple TargetFrameworks values), add the following lines right after the `PropertyGroup` which defines ``: ```xml ``` + The file should then look like this: + ```xml @@ -65,8 +68,10 @@ Considering that during development, it is common to work on a single platform a ``` + > [!NOTE] > If the template is created with `dotnet new`, the path will instead be `../targetframework-override.props` + 1. Create a copy of the file `solution-config.props.sample` next to itself, and name it `solution-config.props` 1. If using git, add this specific file to the `.gitignore` so it never gets committed. This way, each developer can keep their own version of the file without corrupting the repository. 1. Commit your changes to the repository. @@ -74,6 +79,7 @@ Considering that during development, it is common to work on a single platform a At this point, your solution is ready for single-TargetFramework use. For example, to work on `net7.0-ios`: + 1. Before opening the solution, open the `solution-config.props` file and uncomment `MyAppTargetFrameworkOverride` to contain `net7.0-ios` 1. Open the `MyApp-Mobile-Only.slnf` solution filter in Visual Studio 2022 1. You should only see the **.Mobile** and **Class Library** projects in your solution From 6995383355ecf8e622a28ebef43d7f043dcb94ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Laban?= Date: Tue, 31 Jan 2023 16:35:28 -0500 Subject: [PATCH 3/3] docs: Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Agnès ZITTE <16295702+agneszitte-nventive@users.noreply.github.com> (cherry picked from commit 42f83167c36d0a5e43e2fab9fc7a8bebe016a51a) --- .../solution-building-single-targetframework.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/doc/articles/guides/solution-building-single-targetframework.md b/doc/articles/guides/solution-building-single-targetframework.md index ea2107e51a30..27bb68787160 100644 --- a/doc/articles/guides/solution-building-single-targetframework.md +++ b/doc/articles/guides/solution-building-single-targetframework.md @@ -3,17 +3,17 @@ uid: Build.Solution.TargetFramework-override --- # Adjust an Uno Solution for a faster build with Visual Studio 2022 -The Uno Platform template provides a cross-targeted Class library which includes multiple target frameworks. While building with the command line `dotnet build -f net7.0-ios` does only build the application's head and the class library for `net7.0-ios`, Visual Studio builds all the target frameworks, [regardless of the project head's target framework](https://developercommunity.visualstudio.com/t/Building-a-cross-targeted-project-with-m/651372). +The Uno Platform template provides a cross-targeted Class library that includes multiple target frameworks. While building with the command line `dotnet build -f net7.0-ios` only builds the application's head and the class library for `net7.0-ios`, Visual Studio builds all the target frameworks, [regardless of the project head's target framework](https://developercommunity.visualstudio.com/t/Building-a-cross-targeted-project-with-m/651372). -Considering that during development, it is common to work on a single platform at a given time, here's a suggested set of modification that can be performed on the solution to restrict the active build platform: +Considering that during development, it is common to work on a single platform at a given time, here's a suggested set of modifications that can be performed on the solution to restrict the active build platform: 1. Let's create a set of solution filters to ensure that individual project heads can be loaded: 1. Create a new app template with **iOS**, **Android**, **WebAssembly** and **Windows** targets selected. 1. Right click on the **.Mobile** and **.Wasm** projects and select **Unload Project** - 1. On the top level Solution node, right click to select **Save As Solution Filter**, name the filter **MyApp-Windows-Only.slnf** - 1. Right click on the **Mobile** project, select **Reload Project** - 1. Unload the **.Windows** project, then save a new solution filter called **MyApp-Mobile- Only.slnf** + 1. On the top level Solution node, right-click to select **Save As Solution Filter**, name the filter **MyApp-Windows-Only.slnf** + 1. Right-click on the **Mobile** project, select **Reload Project** + 1. Unload the **.Windows** project, then save a new solution filter called **MyApp-Mobile-Only.slnf** 1. Repeat the operation with the **.Wasm** project, with a solution filter called **MyApp-Wasm-Only.slnf** These solution filters will prevent Visual Studio to restore NuGet packages for TargetFrameworks that will be ignored by the configuration done below. @@ -37,7 +37,7 @@ Considering that during development, it is common to work on a single platform a