From 8499346550a9958666ad907e5d1b353c1aead0f2 Mon Sep 17 00:00:00 2001 From: Yabo Hu Date: Thu, 10 Oct 2024 16:58:32 +0800 Subject: [PATCH] use alternative way to generate assemblyinfo.cs (#1387) * use alternative way to generate assemblyinfo.cs * disable generate assemblyinfo by dotnet * forgot await * Update powershell/generators/csproj.ts * check if assemblyinfopath --------- Co-authored-by: Yeming Liu <11371776+isra-fel@users.noreply.github.com> --- powershell/generators/AssemblyInfo.ts | 30 ++++++++++++++++++++ powershell/generators/csproj.ts | 18 +----------- powershell/plugins/powershell-v2.ts | 3 +- powershell/resources/assets/build-module.ps1 | 7 ----- 4 files changed, 33 insertions(+), 25 deletions(-) create mode 100644 powershell/generators/AssemblyInfo.ts diff --git a/powershell/generators/AssemblyInfo.ts b/powershell/generators/AssemblyInfo.ts new file mode 100644 index 0000000000..5430716273 --- /dev/null +++ b/powershell/generators/AssemblyInfo.ts @@ -0,0 +1,30 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +import { Project } from '../internal/project'; + +export async function generateAssemblyInfo(project: Project) { + if (!project.azure || !project.assemblyInfoPath) { + return; + } + + const info = `${project.csharpCommentHeaderForCsharp} + +using System; +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +[assembly: System.Reflection.AssemblyCompanyAttribute("${project.assemblyCompany}")] +[assembly: System.Reflection.AssemblyCopyrightAttribute("${project.assemblyCopyright}")] +[assembly: System.Reflection.AssemblyProductAttribute("${project.assemblyProduct}")] +[assembly: System.Reflection.AssemblyTitleAttribute("${project.assemblyProduct} - ${project.title}")] +[assembly: System.Reflection.AssemblyFileVersionAttribute("0.1.0.0")] +[assembly: System.Reflection.AssemblyVersionAttribute("0.1.0.0")] +[assembly: System.Runtime.InteropServices.ComVisibleAttribute(false)] +[assembly: System.CLSCompliantAttribute(false)]`; + + project.state.writeFile(project.assemblyInfoPath, info, undefined, 'source-file-csharp'); +} \ No newline at end of file diff --git a/powershell/generators/csproj.ts b/powershell/generators/csproj.ts index e06535a328..5f48aa9958 100644 --- a/powershell/generators/csproj.ts +++ b/powershell/generators/csproj.ts @@ -15,22 +15,6 @@ export async function generateCsproj(project: Project) { TRACE;RELEASE;NETSTANDARD;SIGN` : ' TRACE;RELEASE;NETSTANDARD'; - const assemblyinfo = project.azure ? ` - ${project.assemblyInfoPath} - ${project.assemblyCompany} - ${project.assemblyProduct} - ${project.assemblyCopyright} - ${project.assemblyProduct} - ${project.title} - - - - <_Parameter1>false - - - <_Parameter1>false - - ` : ''; - project.state.writeFile(project.csproj, ` @@ -39,6 +23,7 @@ export async function generateCsproj(project: Project) { netstandard2.0 Library ${project.dllName} + false ${project.projectNamespace} true false @@ -52,7 +37,6 @@ export async function generateCsproj(project: Project) { true - ${assemblyinfo} false TRACE;DEBUG;NETSTANDARD diff --git a/powershell/plugins/powershell-v2.ts b/powershell/plugins/powershell-v2.ts index c5af572187..212aabd614 100644 --- a/powershell/plugins/powershell-v2.ts +++ b/powershell/plugins/powershell-v2.ts @@ -25,9 +25,9 @@ import { generateGitAttributes } from '../generators/gitattributes'; import { generateReadme } from '../generators/readme'; import { generateScriptCmdlets } from '../generators/script-cmdlet'; import { TspHost } from '../utils/tsp-host'; -import { State } from '../internal/state'; import { ModelState } from '../utils/model-state'; import { PwshModel } from '../utils/PwshModel'; +import { generateAssemblyInfo } from '../generators/AssemblyInfo'; const sourceFileCSharp = 'source-file-csharp'; const resources = `${__dirname}/../../resources`; @@ -138,6 +138,7 @@ export async function powershellV2(service: Host | TspHost, state?: ModelState