Skip to content

Commit e1c53c2

Browse files
authored
Update azure-powershell-developer-guide.md (#22785)
1 parent 129d898 commit e1c53c2

File tree

1 file changed

+42
-41
lines changed

1 file changed

+42
-41
lines changed

documentation/development-docs/azure-powershell-developer-guide.md

Lines changed: 42 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22

33
The Azure PowerShell Developer Guide was created to help with the development and testing of Azure PowerShell cmdlets. This guide contains information on how to set up your environment, create a new project, implement cmdlets, record and run tests, and more.
44

5-
**Note: Except for the way described in this page, There is a new way to generate PowerShell modules through AutoRest PowerShell generator. Refer to [Autorest PowerShell Generator](#autorest-powershell-generator).**
5+
**Note: this guide only applies to the SDK-based development approach. For the generator-based approach, please refer to [Autorest PowerShell Generator](#autorest-powershell-generator).**
66

7-
# Table of Contents
7+
## Table of Contents
88

9-
- [Azure PowerShell Developer Guide](#azure-powershell-developer-guide)
109
- [Table of Contents](#table-of-contents)
1110
- [Prerequisites](#prerequisites)
1211
- [Environment Setup](#environment-setup)
@@ -35,7 +34,7 @@ The Azure PowerShell Developer Guide was created to help with the development an
3534
- [Scenario Tests](#scenario-tests)
3635
- [Adding Test Project](#adding-test-project)
3736
- [Adding Scenario Tests](#adding-scenario-tests)
38-
- [Use local files in test](#use-local-files-in-test)
37+
- [Use local files in test](#use-local-files-in-test)
3938
- [Using Active Directory](#using-active-directory)
4039
- [AD Scenario Tests](#ad-scenario-tests)
4140
- [Recording/Running Tests](#recordingrunning-tests)
@@ -45,24 +44,24 @@ The Azure PowerShell Developer Guide was created to help with the development an
4544
- [Publish to PowerShell Gallery](#publish-to-powershell-gallery)
4645
- [AutoRest PowerShell Generator](#autorest-powershell-generator)
4746

48-
# Prerequisites
47+
## Prerequisites
4948

5049
The following prerequisites should be completed before contributing to the Azure PowerShell repository:
5150

52-
- Install [Visual Studio 2019 or above](https://www.visualstudio.com/downloads/)
51+
- Install [Visual Studio 2022 or above](https://www.visualstudio.com/downloads/)
5352
- Install the latest version of [Git](https://git-scm.com/downloads)
5453
- Install the [`platyPS` module](help-generation.md#Installing-platyPS)
5554
- Install [PSScriptAnalyzer](https://github.com/PowerShell/PSScriptAnalyzer#installation)
56-
- Install [**.NET Core 3.1, the Latest .NET, and .NET Framework Dev Pack 4.7.2**](https://dotnet.microsoft.com/en-us/download/dotnet) or greater
55+
- Install [**.NET SDK 6, and .NET Framework Dev Pack 4.7.2**](https://dotnet.microsoft.com/en-us/download/dotnet) or greater
5756
- Install [PowerShell 7](https://github.com/PowerShell/PowerShell/releases/latest)
5857
- Set the PowerShell [execution policy](https://technet.microsoft.com/en-us/library/ee176961.aspx) to **Unrestricted** for the following versions of PowerShell:
5958
- `C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe`
6059
- `C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe`
6160
- `C:\Program Files\PowerShell\{{version}}\pwsh.exe`
6261

63-
# Environment Setup
62+
## Environment Setup
6463

65-
## GitHub Basics
64+
### GitHub Basics
6665

6766
If you don't have experience with Git and GitHub, some of the terminology and process can be confusing. [Here is a guide to understanding the GitHub flow](https://guides.github.com/introduction/flow/) and [here is a guide to understanding the basic Git commands](https://education.github.com/git-cheat-sheet-education.pdf).
6867

@@ -88,7 +87,7 @@ Then, to pull changes from the **main** branch in _Azure/azure-powershell_ into
8887
git pull upstream main
8988
```
9089

91-
## Building the Environment
90+
### Building the Environment
9291

9392
_Note_: to build the environment locally, you need `platyPS` install on your machine. Please see the [Prerequisites](#prerequisites) section for details on how to install this module.
9493

@@ -104,15 +103,15 @@ Alternatively, you can open any command prompt (Command Prompt, Windows PowerShe
104103
PS C:\azure-powershell> dotnet msbuild build.proj
105104
```
106105

107-
## Generating Help
106+
### Generating Help
108107

109108
We build the `dll-Help.xml` files (used to display the help content for cmdlets in PowerShell) from markdown using the `platyPS` module. Since this help generation step can take 10-15 minutes, it is a separate part of the command line build process. Run this to generate help:
110109

111110
```
112111
msbuild build.proj /t:GenerateHelp
113112
```
114113

115-
## Running Static Analysis
114+
### Running Static Analysis
116115

117116
To keep consistency across our modules, we've implemented a static analysis system. This verifies various aspects (dependencies, breaking changes, etc.) for your module. Run this command to execute static analysis validation for the built modules:
118117

@@ -122,7 +121,7 @@ msbuild build.proj /t:StaticAnalysis
122121

123122
_Note_: this can add 10-15 minutes to your build time due to help generation.
124123

125-
## Running Tests
124+
### Running Tests
126125

127126
Launch `VS Developer Command Prompt` and run the following command (from the root of the repository) to run all of the tests in playback:
128127

@@ -136,15 +135,15 @@ Alternatively, you can open any command prompt (Command Prompt, Windows PowerShe
136135
PS C:\azure-powershell> dotnet msbuild build.proj /t:Test
137136
```
138137

139-
# Before Adding a New Project
138+
## Before Adding a New Project
140139

141-
## .NET SDK
140+
### .NET SDK
142141

143142
Before adding a new project to Azure PowerShell, you must have generated an [SDK for .NET](https://github.com/Azure/azure-sdk-for-net) using [AutoRest](https://github.com/Azure/autorest) for your service, and it must have been merged into the repository.
144143

145144
For more information about on-boarding a new library in the SDK for .NET repository, click [here](https://github.com/Azure/azure-sdk-for-net#to-on-board-new-libraries).
146145

147-
## Design Review
146+
### Design Review
148147

149148
Before development, you must meet with the Azure PowerShell team to have a design review for your proposed PowerShell cmdlets. We advise that this review is held no earlier than three weeks out from code complete of the release you want to ship the cmdlets with. For a small number of cmdlet changes and/or additions, an email containing the markdown files for the proposed changes is suggested. For a large number of changes and/or additions, a meeting is required with the Azure PowerShell team.
150149

@@ -156,19 +155,19 @@ _Note_: You will need to be part of the `GitHub Azure` org to see this repositor
156155

157156
We recommend using the `platyPS` module to easily generate markdown files that contains the above information and including the files in the design submission.
158157

159-
## Point of Contact
158+
### Point of Contact
160159

161160
You must provide a contact (Microsoft alias + GitHub alias) on your team that is responsible for handling issues with your SDK and cmdlets, as well as open source contributions to your code.
162161

163162
Also, members of your team (who are involved with the SDKs) are advised to join the [Microsoft Teams Azure SDK team](https://teams.microsoft.com/l/team/19%3a9b93b9f4bd1540a486e5ef1a82a74637%40thread.skype/conversations?groupId=da8d67c5-f19d-4799-b158-5dbbef868d49&tenantId=72f988bf-86f1-41af-91ab-2d7cd011db47), and join the **adxsdkpartners** alias on idweb.
164163

165-
# Setting Up a New Project
164+
## Setting Up a New Project
166165

167-
## Getting Started
166+
### Getting Started
168167

169168
When adding a new project, please follow these guidelines:
170169

171-
### Creating the Project
170+
#### Creating the Project
172171

173172
Add a new folder under `src` with your service specific name (_e.g.,_ `Compute`, `Sql`, `Websites`).
174173

@@ -208,27 +207,29 @@ If you have not generated your AutoRest SDK yet, remove this entry for now.
208207

209208
Right click on the project and select `Reload project`, and then build the solution by either right clicking on the solution and selecting `Rebuild Solution` or, from the top of Visual Studio, selecting `Build > Rebuild Solution`. If the build does not succeed, open the `.csproj` file and ensure there are no errors.
210209

211-
### Adding Project References
210+
#### Adding Project References
212211

213212
There are a few existing projects that need to be added before developing any cmdlets. To add a project to the solution, right click on the solution in `Solution Explorer` and select `Add > Existing Project`. This allows you to navigate through folders to find the `.csproj` of the project you want to add. Once a project is added to your solution, you can add it as a reference to the `<SERVICE>` project by right clicking on `<SERVICE>` and selecting `Add > Reference`. This opens the `Reference Manager` window, and once you have selected the `Projects > Solution` option on the left side of the window, you are able to select which projects you want to reference in `<SERVICE>` by checking the box to the left of the name.
214213

215-
# Creating Cmdlets
214+
## Creating Cmdlets
216215

217-
## PowerShell Cmdlet Design Guidelines
216+
### PowerShell Cmdlet Design Guidelines
218217

219218
Please check out the [_Cmdlet Best Practices_](./design-guidelines/cmdlet-best-practices.md) document for more information on how to create cmdlets that follow the PowerShell guidelines.
220219

221-
## Exceptions Guidelines
220+
### Exceptions Guidelines
222221

223222
Azure PowerShell defines most commonly used exceptions. Developers working on Azure PowerShell should use these exceptions during development, rather than other more generic exceptions.
224223
Refer to [_Azure PowerShell Exceptions_](./design-guidelines/azure-powershell-exceptions.md) for more information on Azure PowerShell Exceptions.
225224

226-
## Enable Running PowerShell when Debugging
225+
### Enable Running PowerShell when Debugging
227226
To import modules automatically when debug has started, follow the below steps:
228-
### Set a StartUp Project
227+
228+
#### Set a StartUp Project
229229
- Choose any project and set it as the startup project in Visual Studio
230230
- Right click on your project in the **Solution Explorer** and select **Set as StartUp project**
231-
### Setup a Debug Profile
231+
232+
#### Setup a Debug Profile
232233
- Please refer to [Debug Page, Project Designer](https://learn.microsoft.com/visualstudio/ide/reference/debug-page-project-designer?view=vs-2022) for how to access the Debug page
233234
- Create a **Excutable** new Debug profile
234235
- For Azure PowerShell, please setup debug profile in the following way
@@ -238,29 +239,29 @@ To import modules automatically when debug has started, follow the below steps:
238239

239240
**Note**: if you do not see all of the changes you made to the cmdlets when importing your module in a PowerShell session (_e.g.,_ a cmdlet you added is not recognized as a cmdlet), you may need to delete any existing Azure PowerShell modules that you have on your machine (installed through the PowerShell Gallery) before you import your module.
240241

241-
## Adding Help Content
242+
### Adding Help Content
242243

243244
All cmdlets that are created must have accompanying help that is displayed when users execute the command `Get-Help <your cmdlet>`.
244245

245246
Each cmdlet has a markdown file that contains the help content that is displayed in PowerShell; these markdown files are created (and maintained) using the platyPS module.
246247

247248
For complete documentation, see [`help-generation.md`](help-generation.md) in the `documentation` folder.
248249

249-
# Adding Tests
250+
## Adding Tests
250251

251252
_Note_: As mentioned in the prerequisites section, set the PowerShell [execution policy](https://technet.microsoft.com/en-us/library/ee176961.aspx) to **Unrestricted** for the following versions of PowerShell:
252253

253254
- `C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe`
254255
- `C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe`
255256
- `C:\Program Files\PowerShell\{{version}}\pwsh.exe`
256257

257-
## Using Azure TestFramework
258+
### Using Azure TestFramework
258259

259260
Please see our guide on [Using Azure TestFramework](../testing-docs/using-azure-test-framework.md) for information on how to setup the appropriate connection string and record tests.
260261

261-
## Scenario Tests
262+
### Scenario Tests
262263

263-
### Adding Test Project
264+
#### Adding Test Project
264265

265266
- Create a new folder called `ScenarioTests`
266267
- Create a new folder called `SessionRecords`
@@ -299,7 +300,7 @@ Please see our guide on [Using Azure TestFramework](../testing-docs/using-azure-
299300
}
300301
```
301302

302-
### Adding Scenario Tests
303+
#### Adding Scenario Tests
303304

304305
- Create a new class in `<SERVICE>.Test`
305306
- The new class must inherit from the `<SERVICE>TestRunner` class in this project.
@@ -331,7 +332,7 @@ CI in DevOps will happens under `Debug` folder. So you need to make sure that th
331332
</ItemGroup>
332333
```
333334

334-
### Using Active Directory
335+
#### Using Active Directory
335336

336337
- Use the `Set-TestEnvironment` cmdlet from `Repo-Tasks.psd1` to setup your connection string
337338
- Alternatively, you can set the following environment variables
@@ -341,32 +342,32 @@ CI in DevOps will happens under `Debug` folder. So you need to make sure that th
341342
> 1. Be sure that you have set the `ExecutionPolicy` to `Unrestricted` on both 32-bit and 64-bit PowerShell environments, as mentioned in the [prerequisites](#prerequisites) at the top
342343
> 2. When recording tests, if you are using a Prod environment, use ServicePrincipalName (SPN) and ServicePrincipalSecret. For more information on creating an SPN, click [here](https://learn.microsoft.com/en-us/azure/azure-resource-manager/resource-group-create-service-principal-portal).
343344
344-
### AD Scenario Tests
345+
#### AD Scenario Tests
345346

346347
Create this environment variables for the AD scenario tests:
347348

348349
- `AZURE_SERVICE_PRINCIPAL` should be a service principal - an application defined in the subscription's tenant - that has management access to the subscription (or at least to a resource group in the tenant)
349350
- `AZURE_SERVICE_PRINCIPAL=UserId=<UserGuid>;Password=<Password>;TenantId=<TenantGuid>;SubscriptionId=<SubscriptionId>`
350351

351-
### Recording/Running Tests
352+
#### Recording/Running Tests
352353

353354
- Set up environment variables using New-TestCredential as described [here](../testing-docs/using-azure-test-framework.md#new-testcredential)
354355
- Run the test in Visual Studio in the Test Explorer window and make sure you got a generated JSON file that matches the test name under the `SessionRecords` folder
355356

356-
# After Development
357+
## After Development
357358

358359
Once all of your cmdlets have been created and the appropriate tests have been added, you can open a pull request in the Azure PowerShell repository to have your cmdlets added to the next release. Please make sure to read [CONTRIBUTING.md](../../CONTRIBUTING.md) for more information on how to open a pull request, clean up commits, make sure appropriate files have been added/changed, and more.
359360

360-
## Change Log
361+
### Change Log
361362

362363
Whenever you make updates to a project, please make sure to update the corresponding service's `ChangeLog.md` file with a snippet of what you changed under the `Upcoming Release` header. This information is later used for the release notes that goes out with each module the next time they are released, and provides users with more information as to what has changed in the module from the previous release. For more information on updating change logs can be found in [`CONTRIBUTING.md`](../../CONTRIBUTING.md#updating-the-change-log)
363364

364-
# Misc
365+
## Misc
365366

366-
## Publish to PowerShell Gallery
367+
### Publish to PowerShell Gallery
367368

368369
To publish your module to the [official PowerShell gallery](http://www.powershellgallery.com/) or the test gallery site, contact the Azure PowerShell team
369370

370-
# AutoRest PowerShell Generator
371+
## AutoRest PowerShell Generator
371372
- [autorest.powershell documentation](https://github.com/Azure/autorest.powershell/tree/master/docs)
372373
- [examples](https://github.com/Azure/azure-powershell/tree/generation/src)

0 commit comments

Comments
 (0)