Skip to content

Commit e2c0f1b

Browse files
authored
Merge pull request #8406 from vladimir-shcherbakov/ps1xml-gen
format.ps1xml generator upgraded to .Net Standard
2 parents 86222cd + 2f9c5d2 commit e2c0f1b

30 files changed

+373
-589
lines changed

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

Lines changed: 66 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -180,18 +180,18 @@ namespace Microsoft.Azure.Commands.Profile.Models
180180

181181
// code omitted for brevity
182182
183-
[Ps1Xml(Label = "Subscription Id", Target = ViewControl.Table)]
183+
[Ps1Xml(Label = "SubscriptionId", Target = ViewControl.Table)]
184184
public string Id { get; set; }
185185

186-
[Ps1Xml(Label = "Subscription Name", Target = ViewControl.Table)]
186+
[Ps1Xml(Label = "Name", Target = ViewControl.Table)]
187187
public string Name { get; set; }
188188

189189
[Ps1Xml(Label = "State", Target = ViewControl.Table)]
190190
public string State { get; set; }
191191

192192
public string SubscriptionId { get { return Id; } }
193193

194-
[Ps1Xml(Label = "Tenant Id", Target = ViewControl.Table)]
194+
[Ps1Xml(Label = "TenantId", Target = ViewControl.Table)]
195195
public string TenantId
196196
{
197197
get
@@ -260,8 +260,8 @@ To specify what goes into the table view - use the **ScriptBlock** attribute pro
260260
{
261261
// code omitted for brevity
262262
263-
[Ps1Xml(Label = "Account Id", Target = ViewControl.Table, ScriptBlock = "$_.Account.Id")]
264-
[Ps1Xml(Label = "Account Type", Target = ViewControl.Table, ScriptBlock = "$_.Account.Type")]
263+
[Ps1Xml(Label = "Account.Id", Target = ViewControl.Table, ScriptBlock = "$_.Account.Id")]
264+
[Ps1Xml(Label = "Account.Type", Target = ViewControl.Table, ScriptBlock = "$_.Account.Type")]
265265
public IAzureAccount Account { get; set; }
266266

267267
// code omitted for brevity
@@ -272,8 +272,8 @@ Note: **$_** symbol in PowerShell means the same as **this** key word means in C
272272

273273
These two attribute will result in 2 column in the table view:
274274
```Ps
275-
Account Id Account Type
276-
========== ============
275+
Account.Id Account.Type
276+
========== ============
277277
```
278278
## GroupBy a property.
279279

@@ -284,7 +284,7 @@ public class PSAzureSubscription : IAzureSubscription
284284

285285
// code omitted for brevity
286286
287-
[Ps1Xml(Label = "Subscription Id", Target = ViewControl.Table, GroupByThis = true)]
287+
[Ps1Xml(Label = "SubscriptionId", Target = ViewControl.Table, GroupByThis = true)]
288288
public string Id { get; set; }
289289

290290
// code omitted for brevity
@@ -298,7 +298,7 @@ public class PSAzureSubscription : IAzureSubscription
298298

299299
// code omitted for brevity
300300
301-
[Ps1Xml(Label = "Subscription Name", Target = ViewControl.Table, Position = 0)]
301+
[Ps1Xml(Label = "Name", Target = ViewControl.Table, Position = 0)]
302302
public string Name { get; set; }
303303

304304
// code omitted for brevity
@@ -309,53 +309,70 @@ This will place the column at the very beginning of the table.
309309

310310
# How to generate format.ps1xml file.
311311

312-
1. First of all you need to [build](https://github.com/Azure/azure-powershell/blob/master/documentation/development-docs/azure-powershell-developer-guide.md#building-the-environment) PowerShell Azure:
313-
314-
```Powershell
315-
PS E:\git\azure-powershell> msbuild build.proj /p:SkipHelp=true
316-
```
317-
318-
* After the build is completed you can find build artifacts in the ```.\artifacts\Debug``` folder:
319-
320-
```Powershell
321-
PS E:\git\azure-powershell> ls .\artifacts\Debug\
312+
## Let's consider how to generate a format.ps1xml file for the Az.Storage and Az.Account modules.
313+
1. Start PowerShell 6
314+
2. Build and import the FormatPs1XmlGenerator module.
315+
* Go to the generator directory
316+
```Powershell
317+
PS C:\Users\you> cd E:\git\azure-powershell\tools\FormatPs1XmlGenerator\
318+
```
319+
* Build the generator solution
320+
```Powershell
321+
PS E:\git\azure-powershell\tools\FormatPs1XmlGenerator> dotnet build
322+
```
323+
* Import the generator module
324+
```Powershell
325+
PS E:\git\azure-powershell\tools\FormatPs1XmlGenerator> Import-Module .\FormatPs1XmlGenerator\bin\Debug\FormatPs1XmlGenerator.psd1
326+
```
327+
328+
3. Build the Az.Storage module.
329+
* Go to the Storage directory
330+
```Powershell
331+
PS C:\Users\you>cd E:\git\azure-powershell\src\Storage
332+
```
333+
* Build the module
334+
```Powershell
335+
PS E:\git\azure-powershell\src\Storage>dotnet build
336+
```
337+
* Go to the repository root folder
338+
```Powershell
339+
PS E:\git\azure-powershell\src\Storage>cd E:\git\azure-powershell\
340+
```
341+
* Check the artifacts folder - all built modules should be there. Since Az.Storage depends on the Az.Accounts module both Az.Accounts and Az.Storage modules should be there:
342+
```Powershell
343+
PS E:\git\azure-powershell> ls .\artifacts\Debug\
322344

323345

324346
Directory: E:\git\azure-powershell\artifacts\Debug
325347

326348

327-
Mode LastWriteTime Length Name
328-
---- ------------- ------ ----
329-
d----- 4/25/2018 4:37 PM ResourceManager
330-
d----- 4/25/2018 4:35 PM ServiceManagement
331-
d----- 4/25/2018 4:35 PM Storage
332-
-a---- 4/25/2018 4:31 PM 11384 Az.psd1
333-
-a---- 4/25/2018 4:50 PM 8708 Az.psm1
334-
335-
```
336-
337-
2. Import the **RepoTask cmdlets**:
338-
339-
```PowerShell
340-
PS E:\git\azure-powershell> Import-Module E:\git\azure-powershell\tools\RepoTasks\RepoTasks.Cmdlets\bin\Debug\RepoTasks.Cmdlets.dll
341-
```
342-
3. Run the **New-FormatPs1Xml** cmdlet.
343-
* The cmdlet has one required argument **-ModulePath** - a path to a module manifest (psd1) file. Since in our example we are using the Get-AzSubscription cmdlet from the Az.Accounts module we need to specify path to the Az.Accounts module manifest which is
344-
```
345-
E:\git\azure-powershell\artifacts\Debug\Az.Accounts\Az.Accounts.psd1
346-
```
347-
* Also with the cmdlet we need to use **-OnlyMarkedProperties** switch.
348-
* You may also want to specify an output path for the generated file with the **-OutputPath** argument. If not specified this is current folder.
349-
350-
```
351-
PS E:\git\azure-powershell> New-FormatPs1Xml -ModulePath .\artifacts\Debug\Az.Accounts\Az.Accounts.psd1 -OnlyMarkedProperties
352-
353-
E:\git\azure-powershell\Microsoft.Azure.Commands.Profile.generated.format.ps1xml
354-
```
355-
* After a successful run the cmdlet outputs the full path to the generated format.ps1xml file.
349+
Mode LastWriteTime Length Name
350+
---- ------------- ------ ----
351+
d----- 1/29/2019 2:18 PM Az.Accounts
352+
d----- 1/29/2019 2:18 PM Az.Storage
353+
```
354+
4. Run the **New-FormatPs1Xml** cmdlet.
355+
* The cmdlet has one required parameter **-ModulePath** - a path to a module manifest (psd1) file.
356+
* Also with the cmdlet we need to use **-OnlyMarkedProperties** switch.
357+
* You may also want to specify an output path for the generated file with the **-OutputPath** argument. If not specified this is current folder.
358+
* After a successful run the cmdlet outputs the full path to the generated format.ps1xml file.
359+
360+
* Below is an example of how to generate a format.ps1xml file for the ```Az.Storage``` module:
361+
```Powershell
362+
PS E:\git\azure-powershell> New-FormatPs1Xml -OnlyMarkedProperties -ModulePath .\artifacts\Debug\Az.Storage\Az.Storage.psd1
363+
E:\git\azure-powershell\Microsoft.Azure.PowerShell.Cmdlets.Storage.Management.generated.format.ps1xml
364+
E:\git\azure-powershell\Microsoft.Azure.PowerShell.Cmdlets.Storage.generated.format.ps1xml
365+
```
366+
* Below is an example of how to generate a format.ps1xml file for the ```Az.Account``` module:
367+
```powershell
368+
PS E:\git\azure-powershell> New-FormatPs1Xml -OnlyMarkedProperties -ModulePath .\artifacts\Debug\Az.Accounts\Az.Accounts.psd1
369+
E:\git\azure-powershell\Microsoft.Azure.PowerShell.Cmdlets.Accounts.generated.format.ps1xml
370+
PS E:\git\azure-powershell>
371+
```
356372

357373
# How to test the format.ps1xml file.
358374

375+
## Let's take a look at how to check the newly created format.ps1xml file for the ```Az.Account``` module.
359376
**Note:** All the paths used in the example in the section are under **_azure-powershell/artifacts/Debug_**
360377

361378
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
@@ -396,7 +413,7 @@ PS C:\> Import-Module E:\git\azure-powershell\artifacts\Debug\Az.Accounts\Az.Acc
396413
```Powershell
397414
PS C:\> Get-AzSubscription
398415

399-
Subscription Id Subscription Name State Tenant Id
416+
SubscriptionId Name State TenantId
400417
--------------- ----------------- ----- ---------
401418
c9cbd920-c00c-427c-852b-c329e824c3a8 Azure SDK Powershell Test Enabled 72f988bf-86f1-41af-91ab-7a64d1d63df5
402419
6b085460-5f21-477e-ba44-4cd9fbd030ef Azure SDK Infrastructure Enabled 72f988bf-86f1-41af-91ab-7a64d1d63df5
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0">
2+
<Import Project="$(MSBuildThisFileDirectory)..\..\..\Repo.props" />
3+
<Import Project="$(RepoTools)Common.Netcore.Dependencies.targets" />
4+
<PropertyGroup>
5+
<TargetFramework>netstandard2.0</TargetFramework>
6+
<AssemblyName>CmdletsForTest</AssemblyName>
7+
<RootNamespace>CmdletsForTest</RootNamespace>
8+
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
9+
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
10+
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
11+
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
12+
<WarningsAsErrors />
13+
<IsPackable>false</IsPackable>
14+
<DelaySign>false</DelaySign>
15+
</PropertyGroup>
16+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
17+
<DefineConstants>TRACE;DEBUG;NETSTANDARD</DefineConstants>
18+
</PropertyGroup>
19+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
20+
<DefineConstants>TRACE;RELEASE;NETSTANDARD</DefineConstants>
21+
</PropertyGroup>
22+
<ItemGroup>
23+
<None Update="Dummy.psd1">
24+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
25+
</None>
26+
</ItemGroup>
27+
</Project>

tools/RepoTasks/RepoTasks.Cmdlets.Tests/Dummy.psd1 renamed to tools/FormatPs1XmlGenerator/CmdletsForTest/Dummy.psd1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Copyright = 'Microsoft Corporation. All rights reserved.'
2222
Description = 'Test'
2323

2424
# Minimum version of the Windows PowerShell engine required by this module
25-
PowerShellVersion = '3.0'
25+
PowerShellVersion = '5.1'
2626

2727
# Name of the Windows PowerShell host required by this module
2828
# PowerShellHostName = ''
@@ -31,7 +31,7 @@ PowerShellVersion = '3.0'
3131
# PowerShellHostVersion = ''
3232

3333
# Minimum version of Microsoft .NET Framework required by this module
34-
DotNetFrameworkVersion = '4.5.2'
34+
DotNetFrameworkVersion = '4.7.2'
3535

3636
# Minimum version of the common language runtime (CLR) required by this module
3737
CLRVersion = '4.0'
@@ -55,7 +55,7 @@ RequiredModules = @()
5555
#FormatsToProcess = ''
5656

5757
# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess
58-
NestedModules = @('.\RepoTasks.CmdletsForTest.dll')
58+
NestedModules = @('.\CmdletsForTest.dll')
5959

6060
# Functions to export from this module
6161
# FunctionsToExport = @()

tools/RepoTasks/RepoTasks.CmdletsForTest/Models/PsDummyOutput1.cs renamed to tools/FormatPs1XmlGenerator/CmdletsForTest/Models/PsDummyOutput1.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
// limitations under the License.
1212
// ----------------------------------------------------------------------------------
1313

14-
15-
namespace RepoTasks.CmdletsForTest.Models
14+
namespace CmdletsForTest.Models
1615
{
1716
using Microsoft.WindowsAzure.Commands.Common.Attributes;
1817

tools/RepoTasks/RepoTasks.CmdletsForTest/Models/PsDummyOutput2.cs renamed to tools/FormatPs1XmlGenerator/CmdletsForTest/Models/PsDummyOutput2.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// ----------------------------------------------------------------------------------
1313

1414

15-
namespace RepoTasks.CmdletsForTest.Models
15+
namespace CmdletsForTest.Models
1616
{
1717
using Microsoft.WindowsAzure.Commands.Common.Attributes;
1818

tools/RepoTasks/RepoTasks.CmdletsForTest/Models/PsDummyOutputTwo.cs renamed to tools/FormatPs1XmlGenerator/CmdletsForTest/Models/PsDummyOutputTwo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// limitations under the License.
1212
// ----------------------------------------------------------------------------------
1313

14-
namespace RepoTasks.CmdletsForTest.Models
14+
namespace CmdletsForTest.Models
1515
{
1616
public class PsDummyOutputTwo
1717
{

tools/RepoTasks/RepoTasks.CmdletsForTest/Models/PsOperation.cs renamed to tools/FormatPs1XmlGenerator/CmdletsForTest/Models/PsOperation.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
using Microsoft.WindowsAzure.Commands.Common.Attributes;
1515

16-
namespace RepoTasks.CmdletsForTest.Models
16+
namespace CmdletsForTest.Models
1717
{
1818
using System.Net;
1919
public class PsOperation

tools/RepoTasks/RepoTasks.CmdletsForTest/TestDummyCommand.cs renamed to tools/FormatPs1XmlGenerator/CmdletsForTest/TestDummyCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// ----------------------------------------------------------------------------------
1313

1414

15-
namespace RepoTasks.CmdletsForTest
15+
namespace CmdletsForTest
1616
{
1717
using Models;
1818
using System;

tools/RepoTasks/RepoTasks.CmdletsForTest/TestDummyCommand1.cs renamed to tools/FormatPs1XmlGenerator/CmdletsForTest/TestDummyCommand1.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// limitations under the License.
1212
// ----------------------------------------------------------------------------------
1313

14-
namespace RepoTasks.CmdletsForTest
14+
namespace CmdletsForTest
1515
{
1616
using System.Management.Automation;
1717
using Models;

tools/RepoTasks/RepoTasks.RemoteWorker/IReflectionWorker.cs renamed to tools/FormatPs1XmlGenerator/FormatPs1XmlGenerator.Test/Constants.cs

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

14-
using System;
15-
using System.Collections.Generic;
16-
17-
namespace RepoTasks.RemoteWorker
14+
namespace FormatPs1XmlGenerator.Test
1815
{
19-
public interface IReflectionWorker
16+
internal class Category
2017
{
21-
Tuple<string, List<string>> BuildFormatPs1Xml(string assemblyPath, string[] cmdlet, bool onlyMarkedProperties);
22-
void Serialize(string filepath);
18+
public const string AcceptanceType = "AcceptanceType";
19+
public const string CheckIn = "CheckIn";
2320
}
2421
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<Import Project="$(MSBuildThisFileDirectory)..\..\Common.Netcore.Dependencies.Test.targets" />
3+
4+
<PropertyGroup>
5+
<TargetFramework>netcoreapp2.1</TargetFramework>
6+
<IsPackable>false</IsPackable>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<ProjectReference Include="..\CmdletsForTest\CmdletsForTest.csproj" />
11+
<ProjectReference Include="..\FormatPs1XmlGenerator\FormatPs1XmlGenerator.csproj" />
12+
</ItemGroup>
13+
14+
</Project>

tools/RepoTasks/RepoTasks.Cmdlets.Tests/NewFormatPs1XmlCommandShould.cs renamed to tools/FormatPs1XmlGenerator/FormatPs1XmlGenerator.Test/NewFormatPs1XmlCommandShould.cs

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

14-
namespace RepoTasks.Cmdlets.Tests
14+
namespace FormatPs1XmlGenerator.Test
1515
{
1616
using System;
1717
using System.Linq;
@@ -21,12 +21,11 @@ namespace RepoTasks.Cmdlets.Tests
2121
using System.IO;
2222
using System.Collections.Generic;
2323
using System.Xml.Linq;
24-
using RemoteWorker;
2524

2625
public class NewFormatPs1XmlCommandShould
2726
{
2827
private const string CmdletName = "New-FormatPs1Xml";
29-
private const string ExpectedAssemblyName = "RepoTasks.CmdletsForTest";
28+
private const string ExpectedAssemblyName = "CmdletsForTest";
3029

3130
[Fact]
3231
[Trait(Category.AcceptanceType, Category.CheckIn)]

0 commit comments

Comments
 (0)