-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
generate assemblyinfo.cs for new module (#1376)
* ignore *.psd1 * ignore assemblyinfo under Properties * add cmdlet newassemblyinfo.cs to create assemblyinfo * protect assemblyinfo.cs * fix * fix * fix * only generate assemblyinfo if is azure
- Loading branch information
Showing
7 changed files
with
90 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
powershell/resources/psruntime/BuildTime/Cmdlets/NewAssemblyInfo.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
using System; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Management.Automation; | ||
using System.Text; | ||
|
||
namespace Microsoft.Rest.ClientRuntime.PowerShell | ||
{ | ||
[Cmdlet("New", "AssemblyInfo")] | ||
[DoNotExport] | ||
public class NewAssemblyInfo : PSCmdlet | ||
{ | ||
private readonly string assemblyInfoPath = Path.Combine("${$project.baseFolder}", "Properties", "AssemblyInfo.cs"); | ||
private const string assemblyName = "${$project.title}"; | ||
private const string assemblyVersion = "${$project.moduleVersion}"; | ||
private const string assemblyCompanyName = "${$project.assemblyCompany}"; | ||
private const string assemblyProduct = "${$project.assemblyProduct}"; | ||
private const string assemblyCopyright = "${$project.assemblyCopyright}"; | ||
protected override void ProcessRecord() | ||
{ | ||
try | ||
{ | ||
if (File.Exists(assemblyInfoPath)) | ||
{ | ||
return; | ||
} | ||
StringBuilder sb = new StringBuilder(); | ||
sb.AppendLine(@" | ||
# ---------------------------------------------------------------------------------- | ||
${$project.pwshCommentHeaderForCsharp} | ||
# ---------------------------------------------------------------------------------- | ||
"); | ||
sb.Append($"{Environment.NewLine}"); | ||
sb.AppendLine("using System;"); | ||
sb.AppendLine("using System.Reflection;"); | ||
sb.AppendLine("using System.Runtime.InteropServices;"); | ||
sb.Append($"{Environment.NewLine}"); | ||
sb.AppendLine($"[assembly: AssemblyTitle(\"Microsoft Azure Powershell - {assemblyName}\")]"); | ||
sb.AppendLine($"[assembly: AssemblyCompany(\"{assemblyCompanyName}\")]"); | ||
sb.AppendLine($"[assembly: AssemblyProduct(\"{assemblyProduct}\")]"); | ||
sb.AppendLine($"[assembly: AssemblyCopyright(\"{assemblyCopyright}\")]"); | ||
sb.Append($"{Environment.NewLine}"); | ||
sb.AppendLine("[assembly: ComVisible(false)]"); | ||
sb.AppendLine("[assembly: CLSCompliant(false)]"); | ||
sb.AppendLine($"[assembly: Guid(\"{Guid.NewGuid()}\")]"); | ||
sb.AppendLine($"[assembly: AssemblyVersion(\"{assemblyVersion}\")]"); | ||
sb.Append($"[assembly: AssemblyFileVersion(\"{assemblyVersion}\")]"); | ||
|
||
FileInfo assemblyInfo = new FileInfo(assemblyInfoPath); | ||
assemblyInfo.Directory.Create(); | ||
File.WriteAllText(assemblyInfo.FullName, sb.ToString()); | ||
} | ||
catch (Exception ee) | ||
{ | ||
Console.WriteLine($"${ee.GetType().Name}/{ee.StackTrace}"); | ||
throw ee; | ||
} | ||
} | ||
} | ||
} |