You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: documentation/development-docs/azure-powershell-developer-guide.md
+42-41Lines changed: 42 additions & 41 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,11 +2,10 @@
2
2
3
3
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.
4
4
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).**
- Set the PowerShell [execution policy](https://technet.microsoft.com/en-us/library/ee176961.aspx) to **Unrestricted** for the following versions of PowerShell:
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).
68
67
@@ -88,7 +87,7 @@ Then, to pull changes from the **main** branch in _Azure/azure-powershell_ into
88
87
git pull upstream main
89
88
```
90
89
91
-
## Building the Environment
90
+
###Building the Environment
92
91
93
92
_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.
94
93
@@ -104,15 +103,15 @@ Alternatively, you can open any command prompt (Command Prompt, Windows PowerShe
104
103
PS C:\azure-powershell> dotnet msbuild build.proj
105
104
```
106
105
107
-
## Generating Help
106
+
###Generating Help
108
107
109
108
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:
110
109
111
110
```
112
111
msbuild build.proj /t:GenerateHelp
113
112
```
114
113
115
-
## Running Static Analysis
114
+
###Running Static Analysis
116
115
117
116
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:
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.
144
143
145
144
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).
146
145
147
-
## Design Review
146
+
###Design Review
148
147
149
148
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.
150
149
@@ -156,19 +155,19 @@ _Note_: You will need to be part of the `GitHub Azure` org to see this repositor
156
155
157
156
We recommend using the `platyPS` module to easily generate markdown files that contains the above information and including the files in the design submission.
158
157
159
-
## Point of Contact
158
+
###Point of Contact
160
159
161
160
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.
162
161
163
162
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.
164
163
165
-
# Setting Up a New Project
164
+
##Setting Up a New Project
166
165
167
-
## Getting Started
166
+
###Getting Started
168
167
169
168
When adding a new project, please follow these guidelines:
170
169
171
-
### Creating the Project
170
+
####Creating the Project
172
171
173
172
Add a new folder under `src` with your service specific name (_e.g.,_`Compute`, `Sql`, `Websites`).
174
173
@@ -208,27 +207,29 @@ If you have not generated your AutoRest SDK yet, remove this entry for now.
208
207
209
208
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.
210
209
211
-
### Adding Project References
210
+
####Adding Project References
212
211
213
212
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.
214
213
215
-
# Creating Cmdlets
214
+
##Creating Cmdlets
216
215
217
-
## PowerShell Cmdlet Design Guidelines
216
+
###PowerShell Cmdlet Design Guidelines
218
217
219
218
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.
220
219
221
-
## Exceptions Guidelines
220
+
###Exceptions Guidelines
222
221
223
222
Azure PowerShell defines most commonly used exceptions. Developers working on Azure PowerShell should use these exceptions during development, rather than other more generic exceptions.
224
223
Refer to [_Azure PowerShell Exceptions_](./design-guidelines/azure-powershell-exceptions.md) for more information on Azure PowerShell Exceptions.
225
224
226
-
## Enable Running PowerShell when Debugging
225
+
###Enable Running PowerShell when Debugging
227
226
To import modules automatically when debug has started, follow the below steps:
228
-
### Set a StartUp Project
227
+
228
+
#### Set a StartUp Project
229
229
- Choose any project and set it as the startup project in Visual Studio
230
230
- 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
232
233
- 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
233
234
- Create a **Excutable** new Debug profile
234
235
- 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:
238
239
239
240
**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.
240
241
241
-
## Adding Help Content
242
+
###Adding Help Content
242
243
243
244
All cmdlets that are created must have accompanying help that is displayed when users execute the command `Get-Help <your cmdlet>`.
244
245
245
246
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.
246
247
247
248
For complete documentation, see [`help-generation.md`](help-generation.md) in the `documentation` folder.
248
249
249
-
# Adding Tests
250
+
##Adding Tests
250
251
251
252
_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:
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.
260
261
261
-
## Scenario Tests
262
+
###Scenario Tests
262
263
263
-
### Adding Test Project
264
+
####Adding Test Project
264
265
265
266
- Create a new folder called `ScenarioTests`
266
267
- Create a new folder called `SessionRecords`
@@ -299,7 +300,7 @@ Please see our guide on [Using Azure TestFramework](../testing-docs/using-azure-
299
300
}
300
301
```
301
302
302
-
### Adding Scenario Tests
303
+
####Adding Scenario Tests
303
304
304
305
- Create a new class in `<SERVICE>.Test`
305
306
- 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
331
332
</ItemGroup>
332
333
```
333
334
334
-
### Using Active Directory
335
+
####Using Active Directory
335
336
336
337
- Use the `Set-TestEnvironment` cmdlet from `Repo-Tasks.psd1` to setup your connection string
337
338
- 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
341
342
> 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
342
343
> 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).
343
344
344
-
### AD Scenario Tests
345
+
####AD Scenario Tests
345
346
346
347
Create this environment variables for the AD scenario tests:
347
348
348
349
-`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)
- Set up environment variables using New-TestCredential as described [here](../testing-docs/using-azure-test-framework.md#new-testcredential)
354
355
- 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
355
356
356
-
# After Development
357
+
##After Development
357
358
358
359
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.
359
360
360
-
## Change Log
361
+
###Change Log
361
362
362
363
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)
363
364
364
-
# Misc
365
+
##Misc
365
366
366
-
## Publish to PowerShell Gallery
367
+
###Publish to PowerShell Gallery
367
368
368
369
To publish your module to the [official PowerShell gallery](http://www.powershellgallery.com/) or the test gallery site, contact the Azure PowerShell team
0 commit comments