Skip to content

Commit

Permalink
use alternative way to generate assemblyinfo.cs (#1387)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
VeryEarly and isra-fel committed Oct 10, 2024
1 parent 1231083 commit bf3293c
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 24 deletions.
30 changes: 30 additions & 0 deletions powershell/generators/AssemblyInfo.ts
Original file line number Diff line number Diff line change
@@ -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');
}
18 changes: 1 addition & 17 deletions powershell/generators/csproj.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,6 @@ export async function generateCsproj(project: Project) {
<DefineConstants>TRACE;RELEASE;NETSTANDARD;SIGN</DefineConstants>` :
' <DefineConstants>TRACE;RELEASE;NETSTANDARD</DefineConstants>';

const assemblyinfo = project.azure ? ` <PropertyGroup>
<GeneratedAssemblyInfoFile>${project.assemblyInfoPath}</GeneratedAssemblyInfoFile>
<Company>${project.assemblyCompany}</Company>
<Product>${project.assemblyProduct}</Product>
<CopyRight>${project.assemblyCopyright}</CopyRight>
<AssemblyTitle>${project.assemblyProduct} - ${project.title}</AssemblyTitle>
</PropertyGroup>
<ItemGroup>
<AssemblyAttribute Include="System.Runtime.InteropServices.ComVisibleAttribute">
<_Parameter1>false</_Parameter1>
</AssemblyAttribute>
<AssemblyAttribute Include="System.CLSCompliantAttribute">
<_Parameter1>false</_Parameter1>
</AssemblyAttribute>
</ItemGroup>` : '';

project.state.writeFile(project.csproj, `<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
Expand All @@ -39,6 +23,7 @@ export async function generateCsproj(project: Project) {
<TargetFramework>netstandard2.0</TargetFramework>
<OutputType>Library</OutputType>
<AssemblyName>${project.dllName}</AssemblyName>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<RootNamespace>${project.projectNamespace}</RootNamespace>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
Expand All @@ -52,7 +37,6 @@ export async function generateCsproj(project: Project) {
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<WarningsAsErrors />
</PropertyGroup>
${assemblyinfo}
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DelaySign>false</DelaySign>
<DefineConstants>TRACE;DEBUG;NETSTANDARD</DefineConstants>
Expand Down
5 changes: 5 additions & 0 deletions powershell/plugins/powershell-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ import { generateGitIgnore } from '../generators/gitignore';
import { generateGitAttributes } from '../generators/gitattributes';
import { generateReadme } from '../generators/readme';
import { generateScriptCmdlets } from '../generators/script-cmdlet';
import { TspHost } from '../utils/tsp-host';
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`;
Expand Down Expand Up @@ -134,6 +138,7 @@ export async function powershellV2(service: Host) {
await generateGitIgnore(project);
await generateGitAttributes(project);
await generateReadme(project);
await generateAssemblyInfo(project);

await generateScriptCmdlets(project);
} catch (E) {
Expand Down
7 changes: 0 additions & 7 deletions powershell/resources/assets/build-module.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,6 @@ if(-not $Debugger) {
$null = Remove-Item -Recurse -ErrorAction SilentlyContinue -Path (Join-Path $binFolder 'Debug'), (Join-Path $binFolder 'Release')
}

if ($isAzure -And '${$project.assemblyInfoPath}') {
$assemblyInfoPath = Join-Path $PSScriptRoot '${$project.assemblyInfoPath}'
$header = '${$project.csharpCommentHeaderForCsharp}'
$content = $header + [Environment]::NewLine + [Environment]::NewLine + (Get-Content $assemblyInfoPath -Raw)
$content | Set-Content $assemblyInfoPath -Force
}

$dll = Join-Path $PSScriptRoot '${$lib.path.relative($project.baseFolder, $project.dll)}'
if(-not (Test-Path $dll)) {
Write-Error "Unable to find output assembly in '$binFolder'."
Expand Down

0 comments on commit bf3293c

Please sign in to comment.