Skip to content

Commit 0a29537

Browse files
authored
[Tools] Apply current structure for Ps1XmlGenerator (Azure#23619)
* apply current structure * polish * Update tools/FormatPs1XmlGenerator/FormatPs1XmlGenerator.Test/FormatPs1XmlGenerator.Test.csproj * Update generate-format.ps1xml-file.md
1 parent a4d9d86 commit 0a29537

File tree

4 files changed

+32
-17
lines changed

4 files changed

+32
-17
lines changed

documentation/development-docs/generate-format.ps1xml-file.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -359,21 +359,21 @@ This will place the column at the very beginning of the table.
359359

360360
* Below is an example of how to generate a format.ps1xml file for the ```Az.Storage``` module:
361361
```Powershell
362-
PS E:\git\azure-powershell> New-FormatPs1Xml -OnlyMarkedProperties -ModulePath .\artifacts\Debug\Az.Storage\Az.Storage.psd1
362+
PS E:\git\azure-powershell> New-FormatPs1Xml -OnlyMarkedProperties -ModulePath .\src\Storage\Storage\Az.Storage.psd1
363363
E:\git\azure-powershell\Microsoft.Azure.PowerShell.Cmdlets.Storage.Management.generated.format.ps1xml
364364
E:\git\azure-powershell\Microsoft.Azure.PowerShell.Cmdlets.Storage.generated.format.ps1xml
365365
```
366366
* Below is an example of how to generate a format.ps1xml file for the ```Az.Account``` module:
367367
```powershell
368-
PS E:\git\azure-powershell> New-FormatPs1Xml -OnlyMarkedProperties -ModulePath .\artifacts\Debug\Az.Accounts\Az.Accounts.psd1
368+
PS E:\git\azure-powershell> New-FormatPs1Xml -OnlyMarkedProperties -ModulePath .\src\Accounts\Accounts\Az.Accounts.psd1
369369
E:\git\azure-powershell\Microsoft.Azure.PowerShell.Cmdlets.Accounts.generated.format.ps1xml
370370
PS E:\git\azure-powershell>
371371
```
372372

373373
# How to test the format.ps1xml file.
374374

375375
## Let's take a look at how to check the newly created format.ps1xml file for the ```Az.Account``` module.
376-
**Note:** All the paths used in the example in the section are under **_azure-powershell/artifacts/Debug_**
376+
**Note:** All the paths used in the example in the section are under **_azure-powershell/src/<module_name>_**
377377

378378
1. **Copy** the generated format.ps1xml file to the built module folder (this is where your module manifest file psd1 is located). In our example the module folder is
379379
```

tools/FormatPs1XmlGenerator/FormatPs1XmlGenerator.Test/FormatPs1XmlGenerator.Test.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2-
<Import Project="$(MSBuildThisFileDirectory)..\..\Common.Netcore.Dependencies.Test.targets" />
2+
<Import Project="$(MSBuildThisFileDirectory)..\..\..\Repo.props" />
3+
<Import Project="$(RepoTools)Common.Netcore.Dependencies.Test.targets" />
34

45
<PropertyGroup>
5-
<TargetFramework>netcoreapp3.1</TargetFramework>
6+
<TargetFramework>netstandard2.0</TargetFramework>
67
<IsPackable>false</IsPackable>
78
</PropertyGroup>
89

tools/FormatPs1XmlGenerator/FormatPs1XmlGenerator.Test/NewFormatPs1XmlCommandShould.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@
1111
// limitations under the License.
1212
// ----------------------------------------------------------------------------------
1313

14+
using System;
15+
using System.Linq;
16+
using System.Management.Automation;
17+
using System.Management.Automation.Runspaces;
18+
using Xunit;
19+
using System.IO;
20+
using System.Collections.Generic;
21+
using System.Xml.Linq;
22+
1423
namespace FormatPs1XmlGenerator.Test
1524
{
16-
using System;
17-
using System.Linq;
18-
using System.Management.Automation;
19-
using System.Management.Automation.Runspaces;
20-
using Xunit;
21-
using System.IO;
22-
using System.Collections.Generic;
23-
using System.Xml.Linq;
24-
2525
public class NewFormatPs1XmlCommandShould
2626
{
2727
private const string CmdletName = "New-FormatPs1Xml";

tools/FormatPs1XmlGenerator/FormatPs1XmlGenerator/NewFormatPs1XmlCommand.cs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
namespace FormatPs1XmlGenerator
1717
{
18+
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
19+
1820
using System;
1921
using System.Collections.Generic;
2022
using System.IO;
@@ -33,6 +35,13 @@ public class NewFormatPs1XmlCommand : PSCmdlet
3335
[Parameter(Position = 3, ValueFromPipeline = false, Mandatory = false)]
3436
public string OutputPath { get; set; }
3537

38+
[Parameter(Position = 4, ValueFromPipeline = false, Mandatory = false)]
39+
[PSArgumentCompleter("Debug", "Release")]
40+
public string Configuration { get; set; } = "Debug";
41+
42+
[Parameter(Position = 5, ValueFromPipeline = false, Mandatory = false)]
43+
public string RepoArtifacts { get; set; } = "artifacts";
44+
3645
[Parameter]
3746
public SwitchParameter Force { get; set; }
3847

@@ -64,7 +73,11 @@ protected override void ProcessRecord()
6473
}
6574
}
6675

67-
foreach (var assemblyPath in GetAssemblyPath(ModulePath))
76+
var moduleName = Path.GetFileNameWithoutExtension(ModulePath);
77+
var RepoRoot = Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(ModulePath))));
78+
var moduleArtifactsOutputPath = Path.Combine(Path.Combine(RepoRoot, Path.Combine(RepoArtifacts, Configuration)), moduleName);
79+
80+
foreach (var assemblyPath in GetAssemblyPath(moduleArtifactsOutputPath, ModulePath))
6881
{
6982
Reflect(assemblyPath);
7083
}
@@ -75,7 +88,7 @@ protected override void ProcessRecord()
7588
}
7689
}
7790

78-
internal static IEnumerable<string> GetAssemblyPath(string manifestPath)
91+
internal static IEnumerable<string> GetAssemblyPath(string artifactsPath, string manifestPath)
7992
{
8093
// parse module (psd1 file) - get assemblies list
8194
var list = new List<string>();
@@ -85,9 +98,10 @@ internal static IEnumerable<string> GetAssemblyPath(string manifestPath)
8598
var result = ps.Invoke();
8699
var moduleInfo = (Hashtable)result[0].BaseObject;
87100
if (moduleInfo == null) return list;
101+
88102
var nestedModules = (object[])moduleInfo["NestedModules"];
89103
var moduleBase = Path.GetDirectoryName(manifestPath) ?? throw new InvalidOperationException("Unable to get module base directory from the manifest path");
90-
list.AddRange(nestedModules.Select(nestedModule => Path.GetFullPath(Path.Combine(moduleBase, nestedModule.ToString()))));
104+
list.AddRange(nestedModules.Select(nestedModule => Path.GetFullPath(Path.Combine(artifactsPath, nestedModule.ToString()))));
91105
}
92106

93107
return list;

0 commit comments

Comments
 (0)