From c445dd27979322b5ac6d144c7307554bb9228317 Mon Sep 17 00:00:00 2001 From: Quentin Berthet Date: Tue, 6 Dec 2022 15:27:04 +0100 Subject: VS: Add Xaml and Resx files to .Net SDK style projects Improve parity with classic MSBuild projects. Fixes: #23415 --- Source/cmVisualStudio10TargetGenerator.cxx | 2 + Tests/RunCMake/VsDotnetSdk/App.xaml | 9 ++ Tests/RunCMake/VsDotnetSdk/App.xaml.cs | 17 +++ Tests/RunCMake/VsDotnetSdk/MainWindow.xaml | 12 +++ Tests/RunCMake/VsDotnetSdk/MainWindow.xaml.cs | 28 +++++ Tests/RunCMake/VsDotnetSdk/Resources.Designer.cs | 63 +++++++++++ Tests/RunCMake/VsDotnetSdk/Resources.resx | 117 +++++++++++++++++++++ Tests/RunCMake/VsDotnetSdk/RunCMakeTest.cmake | 1 + .../VsDotnetSdk/VsDotnetSdkXamlFiles-check.cmake | 56 ++++++++++ .../VsDotnetSdk/VsDotnetSdkXamlFiles.cmake | 48 +++++++++ 10 files changed, 353 insertions(+) create mode 100644 Tests/RunCMake/VsDotnetSdk/App.xaml create mode 100644 Tests/RunCMake/VsDotnetSdk/App.xaml.cs create mode 100644 Tests/RunCMake/VsDotnetSdk/MainWindow.xaml create mode 100644 Tests/RunCMake/VsDotnetSdk/MainWindow.xaml.cs create mode 100644 Tests/RunCMake/VsDotnetSdk/Resources.Designer.cs create mode 100644 Tests/RunCMake/VsDotnetSdk/Resources.resx create mode 100644 Tests/RunCMake/VsDotnetSdk/VsDotnetSdkXamlFiles-check.cmake create mode 100644 Tests/RunCMake/VsDotnetSdk/VsDotnetSdkXamlFiles.cmake diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index ef4bcf8..f5396f4 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -991,6 +991,8 @@ void cmVisualStudio10TargetGenerator::WriteSdkStyleProjectFile( this->WriteDotNetDocumentationFile(e0); this->WriteAllSources(e0); + this->WriteEmbeddedResourceGroup(e0); + this->WriteXamlFilesGroup(e0); this->WriteDotNetReferences(e0); this->WritePackageReferences(e0); this->WriteProjectReferences(e0); diff --git a/Tests/RunCMake/VsDotnetSdk/App.xaml b/Tests/RunCMake/VsDotnetSdk/App.xaml new file mode 100644 index 0000000..156e0fc --- /dev/null +++ b/Tests/RunCMake/VsDotnetSdk/App.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/Tests/RunCMake/VsDotnetSdk/App.xaml.cs b/Tests/RunCMake/VsDotnetSdk/App.xaml.cs new file mode 100644 index 0000000..df2669e --- /dev/null +++ b/Tests/RunCMake/VsDotnetSdk/App.xaml.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Data; +using System.Linq; +using System.Threading.Tasks; +using System.Windows; + +namespace Example +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + } +} diff --git a/Tests/RunCMake/VsDotnetSdk/MainWindow.xaml b/Tests/RunCMake/VsDotnetSdk/MainWindow.xaml new file mode 100644 index 0000000..9a8597d --- /dev/null +++ b/Tests/RunCMake/VsDotnetSdk/MainWindow.xaml @@ -0,0 +1,12 @@ + + + + + diff --git a/Tests/RunCMake/VsDotnetSdk/MainWindow.xaml.cs b/Tests/RunCMake/VsDotnetSdk/MainWindow.xaml.cs new file mode 100644 index 0000000..7d059ed --- /dev/null +++ b/Tests/RunCMake/VsDotnetSdk/MainWindow.xaml.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace Example +{ + /// + /// Interaction logic for MainWindow.xaml + /// + public partial class MainWindow : Window + { + public MainWindow() + { + InitializeComponent(); + } + } +} diff --git a/Tests/RunCMake/VsDotnetSdk/Resources.Designer.cs b/Tests/RunCMake/VsDotnetSdk/Resources.Designer.cs new file mode 100644 index 0000000..58ac7d0 --- /dev/null +++ b/Tests/RunCMake/VsDotnetSdk/Resources.Designer.cs @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Properties { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + public class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + public static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + public static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + } +} diff --git a/Tests/RunCMake/VsDotnetSdk/Resources.resx b/Tests/RunCMake/VsDotnetSdk/Resources.resx new file mode 100644 index 0000000..ea9cbcd --- /dev/null +++ b/Tests/RunCMake/VsDotnetSdk/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + diff --git a/Tests/RunCMake/VsDotnetSdk/RunCMakeTest.cmake b/Tests/RunCMake/VsDotnetSdk/RunCMakeTest.cmake index 22e2bb3..34259b7 100644 --- a/Tests/RunCMake/VsDotnetSdk/RunCMakeTest.cmake +++ b/Tests/RunCMake/VsDotnetSdk/RunCMakeTest.cmake @@ -6,6 +6,7 @@ run_cmake(VsDotnetSdkCustomCommandsSource) run_cmake(VsDotnetSdkStartupObject) run_cmake(VsDotnetSdkDefines) run_cmake(DotnetSdkVariables) +run_cmake(VsDotnetSdkXamlFiles) function(run_VsDotnetSdk) set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/VsDotnetSdk-build) diff --git a/Tests/RunCMake/VsDotnetSdk/VsDotnetSdkXamlFiles-check.cmake b/Tests/RunCMake/VsDotnetSdk/VsDotnetSdkXamlFiles-check.cmake new file mode 100644 index 0000000..3e2c6de --- /dev/null +++ b/Tests/RunCMake/VsDotnetSdk/VsDotnetSdkXamlFiles-check.cmake @@ -0,0 +1,56 @@ +set(vcProjectFile "${RunCMake_TEST_BINARY_DIR}/dotNetSdkWpfApp.csproj") +if(NOT EXISTS "${vcProjectFile}") + set(RunCMake_TEST_FAILED "Project file ${vcProjectFile} does not exist.") + return() +endif() + +set(inAppDefinition FALSE) +set(inPageDefinition FALSE) +set(inResourceDefinition FALSE) +set(xamlAppDefinitionSet FALSE) +set(xamlPageSet FALSE) +set(resourcesSet FALSE) + +file(STRINGS "${vcProjectFile}" lines) +foreach(line IN LISTS lines) + if(NOT inAppDefinition AND line MATCHES "^ *]*>") + set(inAppDefinition TRUE) + elseif(inAppDefinition AND line MATCHES "^ *([^<>]+)$") + if("${CMAKE_MATCH_1}" STREQUAL "App.xaml") + message(STATUS "dotNetSdkWpfApp.csproj has app definition set") + set(xamlAppDefinitionSet TRUE) + set(inAppDefinition FALSE) + endif() + elseif(NOT inPageDefinition AND line MATCHES "^ *]*>") + set(inPageDefinition TRUE) + elseif(inPageDefinition AND line MATCHES "^ *([^<>]+)$") + if("${CMAKE_MATCH_1}" STREQUAL "MainWindow.xaml") + message(STATUS "dotNetSdkWpfApp.csproj has main window page set") + set(xamlPageSet TRUE) + set(inPageDefinition FALSE) + endif() + elseif(NOT inResourceDefinition AND line MATCHES "^ *]*>") + set(inResourceDefinition TRUE) + elseif(inResourceDefinition AND line MATCHES "^ *([^<>]+)$") + if("${CMAKE_MATCH_1}" STREQUAL "Resources.resx") + message(STATUS "dotNetSdkWpfApp.csproj has embedded resources set") + set(resourcesSet TRUE) + set(inResourceDefinition FALSE) + endif() + endif() +endforeach() + +if(NOT xamlAppDefinitionSet) + set(RunCMake_TEST_FAILED "Xaml App definition not set correctly.") + return() +endif() + +if(NOT xamlPageSet) + set(RunCMake_TEST_FAILED "Xaml Page not set correctly.") + return() +endif() + +if(NOT resourcesSet) + set(RunCMake_TEST_FAILED "resources not set correctly.") + return() +endif() diff --git a/Tests/RunCMake/VsDotnetSdk/VsDotnetSdkXamlFiles.cmake b/Tests/RunCMake/VsDotnetSdk/VsDotnetSdkXamlFiles.cmake new file mode 100644 index 0000000..8faf3a7 --- /dev/null +++ b/Tests/RunCMake/VsDotnetSdk/VsDotnetSdkXamlFiles.cmake @@ -0,0 +1,48 @@ +enable_language(CSharp) + +if(NOT CMAKE_CSharp_COMPILER) + return() +endif() + +include(CSharpUtilities) + +add_executable(dotNetSdkWpfApp) +target_sources(dotNetSdkWpfApp + PRIVATE + App.xaml + App.xaml.cs + MainWindow.xaml + MainWindow.xaml.cs + Resources.Designer.cs + Resources.resx) + +csharp_set_xaml_cs_properties( + App.xaml + App.xaml.cs + MainWindow.xaml + MainWindow.xaml.cs) + +csharp_set_designer_cs_properties( + Resources.Designer.cs + Resources.resx) + +set_target_properties(dotNetSdkWpfApp + PROPERTIES + DOTNET_SDK "Microsoft.NET.Sdk" + DOTNET_TARGET_FRAMEWORK "net5.0") + +set_property(SOURCE App.xaml PROPERTY VS_XAML_TYPE "ApplicationDefinition") + +set_property(TARGET dotNetSdkWpfApp PROPERTY VS_DOTNET_REFERENCES + "Microsoft.CSharp" + "PresentationCore" + "PresentationFramework" + "System" + "System.Core" + "System.Data" + "System.Data.DataSetExtensions" + "System.Net.Http" + "System.Xaml" + "System.Xml" + "System.Xml.Linq" + "WindowsBase") -- cgit v0.12