Browse Source

Merge topic 'vs-output-name-net-sdk'

66bd326e28 VS: Use OUTPUT_NAME in DOTNET_SDK projects

Acked-by: Kitware Robot <[email protected]>
Merge-request: !9808
Brad King 1 year ago
parent
commit
d3518bbb17

+ 16 - 7
Source/cmVisualStudio10TargetGenerator.cxx

@@ -1004,6 +1004,8 @@ void cmVisualStudio10TargetGenerator::WriteSdkStyleProjectFile(
     ConvertToWindowsSlash(outDir);
     e1.Element("OutputPath", outDir);
 
+    e1.Element("AssemblyName", GetAssemblyName(config));
+
     Options& o = *(this->ClOptions[config]);
     OptionsHelper oh(o, e1);
     oh.OutputFlagMap();
@@ -1609,13 +1611,7 @@ void cmVisualStudio10TargetGenerator::WriteMSToolConfigurationValuesManaged(
 
   this->WriteMSToolConfigurationValuesCommon(e1, config);
 
-  std::string postfixName =
-    cmStrCat(cmSystemTools::UpperCase(config), "_POSTFIX");
-  std::string assemblyName = this->GeneratorTarget->GetOutputName(
-    config, cmStateEnums::RuntimeBinaryArtifact);
-  if (cmValue postfix = this->GeneratorTarget->GetProperty(postfixName)) {
-    assemblyName += *postfix;
-  }
+  std::string assemblyName = GetAssemblyName(config);
   e1.Element("AssemblyName", assemblyName);
 
   if (cmStateEnums::EXECUTABLE == this->GeneratorTarget->GetType()) {
@@ -3274,6 +3270,19 @@ std::string cmVisualStudio10TargetGenerator::GetTargetOutputName() const
   return cmStrCat(nameComponents.prefix, nameComponents.base);
 }
 
+std::string cmVisualStudio10TargetGenerator::GetAssemblyName(
+  std::string const& config) const
+{
+  std::string postfixName =
+    cmStrCat(cmSystemTools::UpperCase(config), "_POSTFIX");
+  std::string assemblyName = this->GeneratorTarget->GetOutputName(
+    config, cmStateEnums::RuntimeBinaryArtifact);
+  if (cmValue postfix = this->GeneratorTarget->GetProperty(postfixName)) {
+    assemblyName += *postfix;
+  }
+  return assemblyName;
+}
+
 bool cmVisualStudio10TargetGenerator::ComputeClOptions()
 {
   return std::all_of(

+ 1 - 0
Source/cmVisualStudio10TargetGenerator.h

@@ -122,6 +122,7 @@ private:
   std::vector<std::string> GetIncludes(std::string const& config,
                                        std::string const& lang) const;
   std::string GetTargetOutputName() const;
+  std::string GetAssemblyName(std::string const& config) const;
 
   bool ComputeClOptions();
   bool ComputeClOptions(std::string const& configName);

+ 1 - 0
Tests/RunCMake/VsDotnetSdk/RunCMakeTest.cmake

@@ -6,6 +6,7 @@ run_cmake(VsDotnetSdkStartupObject)
 run_cmake(VsDotnetSdkDefines)
 run_cmake(DotnetSdkVariables)
 run_cmake(VsDotnetSdkXamlFiles)
+run_cmake(VsDotnetSdkAssemblyName)
 
 function(run_VsDotnetSdk)
   set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/VsDotnetSdk-build)

+ 22 - 0
Tests/RunCMake/VsDotnetSdk/VsDotnetSdkAssemblyName-check.cmake

@@ -0,0 +1,22 @@
+set(csProjectFile ${RunCMake_TEST_BINARY_DIR}/foo.csproj)
+
+if(NOT EXISTS "${csProjectFile}")
+  set(RunCMake_TEST_FAILED "Project file ${csProjectFile} does not exist.")
+  return()
+endif()
+
+set(hasAssemblyName FALSE)
+
+file(STRINGS "${csProjectFile}" lines)
+
+foreach(line IN LISTS lines)
+  if(NOT inLib1)
+    if(line MATCHES "<AssemblyName>longer name</AssemblyName>")
+      set(hasAssemblyName TRUE)
+    endif()
+  endif()
+endforeach()
+
+if(NOT hasAssemblyName)
+  set(RunCMake_TEST_FAILED "<AssemblyName> not found in ${csProjectFile}.")
+endif()

+ 9 - 0
Tests/RunCMake/VsDotnetSdk/VsDotnetSdkAssemblyName.cmake

@@ -0,0 +1,9 @@
+enable_language(CSharp)
+
+if(NOT CMAKE_CSharp_COMPILER)
+    return()
+endif()
+
+set(CMAKE_DOTNET_SDK "Microsoft.NET.Sdk")
+add_library(foo SHARED lib1.cs)
+set_target_properties(foo PROPERTIES OUTPUT_NAME "longer name")