-
Notifications
You must be signed in to change notification settings - Fork 8.1k
How to create cmdlet w/dotnet CLI #5117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to create cmdlet w/dotnet CLI #5117
Conversation
markekraus
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! This is very helpful and answers some questions I personally had. There are several things that need to be updated and also a few suggestions.
|
|
||
| ## Prerequisites | ||
| * Download and install the [.NET Core 2.0 SDK][net-core-sdk] for your operating system. | ||
| On Linux, I recommend using a package manager to install the SDK. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably change to It is recommended to use a package manager to install the SDK on Linux or something similar. Documentation should not use first person.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
| ``` | ||
|
|
||
| 5. Load the binary and invoke the new command: | ||
| ``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add powershell formatting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
| 1. Copy `mymodule.dll` to a folder on a Windows machine. | ||
|
|
||
| 2. Import the module: | ||
| ``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add powershell formatting
| Note: the module should load without errors. | ||
|
|
||
| 3. Execute the Write-TimestampedMessage command: | ||
| ``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add powershell formatting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
| If you install the .NET Core 2.0 SDK on Windows, you | ||
| can find the implementation version of netstandard.dll for .NET 4.6.1 in the following directory: | ||
| `C:\Program Files\dotnet\sdk\2.0.0\Microsoft\Microsoft.NET.Build.Extensions\net461\lib`. | ||
| If you copy the netstandard.dll from this directory to the directory containing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
code escape netstandard.dll
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
| dotnet add package PowerShellStandard.Library --version 3.0.0-preview-01 | ||
| ``` | ||
|
|
||
| 3. Add the source code for a PowerShell command by opening the Class1.cs file in an editor and adding the following code: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code escape Class1.cs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
| can find the implementation version of netstandard.dll for .NET 4.6.1 in the following directory: | ||
| `C:\Program Files\dotnet\sdk\2.0.0\Microsoft\Microsoft.NET.Build.Extensions\net461\lib`. | ||
| If you copy the netstandard.dll from this directory to the directory containing | ||
| mymodule.dll, the `Write-TimestampedMessage` command will work. Let's try that. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
code escape mymodule.dll
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
| ``` | ||
|
|
||
| This error indicates that the mymodule.dll assembly can't find the implementation version of the | ||
| netstandard.dll for the .NET Framework. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
code escape netstandard.dll
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
| + FullyQualifiedErrorId : System.IO.FileNotFoundException | ||
| ``` | ||
|
|
||
| This error indicates that the mymodule.dll assembly can't find the implementation version of the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
code escape mymodule.dll
| mymodule.dll, the `Write-TimestampedMessage` command will work. Let's try that. | ||
|
|
||
| 1. Start a new Windows PowerShell console. Remember that once a binary assembly is loaded into | ||
| PowerShell it can't be unloaded. Restarting PowerShell is necessary to get it to reload mymodule.dll. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
code escape mymodule.dll
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
|
It looks like you may want to code escape occurrences of |
|
@markekraus RE code escpaping |
| ``` | ||
|
|
||
| 3. Add the [PowerShell Standard Library][ps-stdlib] package to the project file. | ||
| This package provides the System.Management.Automation assembly. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code escape System.Management.Automation
|
/cc @anmenaga This PR has some commonalities with #5096. |
|
@daxian-dbw RE PR # - fixed. |
|
@markekraus RE using cd bin/Debug/netstandard2.0I'm considering removing the |
|
@rkeithhill that's because it should be for the ones that are calling non-PowerShell commands (like Set-Location "bin/Debug/netstandard2.0"
Import-Module "./mymodule.dll"
Write-TimestampedMessage "Test message"or split them out: cd bin/Debug/netstandard2.0(pwsh) Import-Module ./mymodule.dll
Write-TimestampedMessage "Test message"but together like this: cd bin/Debug/netstandard2.0Import-Module ./mymodule.dll
Write-TimestampedMessage "Test message" |
|
@markekraus No one but n00bs quote paths unless there's a space in the path or they tab-complete a path with spaces. And "some" power users will escape a space if there's only one instead of quoting the path. :-) Ditto for That said, I'll quote the path just to make the stupid syntax highlighter happy. |
|
@rkeithhill well.. that's completely inaccurate, but opinions on that aside... I don't think the syntax highlighting is that bad and one reason you want that in is that GitHub is not the only venue these are viewed. In VS Code you get AMAZING syntax highlighting for these. So if it looks a little iffy on GitHub that's fine. |
|
Yeah, VSCode is where I'm editing this doc. BTW thanks for all your feedback. |
Got burned testing on a machine that had 1.0.1 installed
Add info on restarting Windows PoweShell if command fails.
|
Sorry guys! I've been furiously editing the doc as I test the procedure on other systems. I'm "done" for a while. I'll let the requested changes batch up a bit before making any more changes. And yeah, I'll rebase squash this PR as it gets closer to final. |
|
Request for feedback. I'm a bit inconsistent between using the term |
|
After reading through this dotnet standard issue about problems with loading .NET Standard 2.0 libraries in .NET 4.6.1 applications, I think perhaps I should just remove the whole Unless and until, Microsoft provides an update to Windows PowerShell 3 and 5.x that provides all the necessary binding redirects, facades and shims (if this is even possible given that Win PS has to deal with add-ins i.e binary modules), maybe our position should be - this works on .NET 4.7.1 and that's that. IOW your binary module's users will have to be on Windows 10 FCU or higher or they will have to update to .NET 4.7.1. If that isn't acceptable, you'll have to multi-target and build for net461 as well as netstandard2.0. I guess that procedure could be the subject of another "how to". |
|
|
||
| ## Create the .NET Standard 2.0 Binary Module | ||
|
|
||
| 1. Verify you are running the 2.0.0 version of the `dotnet` CLI. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make sure you have added this file to the markdown syntax tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
|
|
||
| 1. Verify you are running the 2.0.0 version of the `dotnet` CLI. | ||
|
|
||
| ``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
code blocks should have an language
TravisEz13
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see comments
Address code block should have language feedback. Address mymodule should be MyModule feedback.
Could not resolve any of the MD029 warnings. From what I can tell , the markdown has a properly incrementing ordered list starting at one.
|
@joeyaiello or @SteveL-MSFT Can you review? |
markekraus
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
|
Are you guys OK with me removing this md file from the markdown.test.ps1 Pester test? I fixed all of the rule errors except for the MD029 errors. Those appear to me to be bogus errors (every list starts with 1 and increments correctly). Either that or perhaps there is a way to suppress this rule? |
|
I think we are using the "One" format. so every item in the list should begin with I think that is actually better long term as it makes it easier to insert items and reorder steps. |
| + FullyQualifiedErrorId : System.IO.FileNotFoundException | ||
| ``` | ||
|
|
||
| If the command worked, congratulations! You're system was probably updated to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're system was probably updated to
A typo. Should be Your
|
@markekraus is right, we are using "One" style. See https://github.com/PowerShell/PowerShell/blob/master/.markdownlint.json |
drewjanderson
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well done, have to get that grammar right!
|
I'm a little perplexed by an "ordered" list where every item is I'd rather change it an unordered list. There is a similar PR for doing this with Visual Studio. It uses an ordered list in the form of |
|
We decided to use the 'One' style because it's easier to add items in the middle of the list in later edits. It will still show as Good point on #5096, I will leave a comment there to get that file added to the markdown test. |
|
OK the following ordered list is from https://github.com/PowerShell/PowerShell/blob/master/docs/dev-process/breaking-change-contract.md So this MD029 rule (set to One) says that list is not right and each item should start with |
| $docsToTest = @( | ||
| './*.md' | ||
| './docs/*.md' | ||
| './docs/cmdlet-example/command-line-simple-example.md' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can change this to './docs/cmdlet-example/*.md', so that #5096 doesn't need to edit markdown.tests.ps1 again.
|
Those 2 markdown files are not captured in |
|
@rkeithhill Some of the rules are to simplify maintenance (or ensure consistency.) Others are to verify syntax. If we think that any of the consistency rules, make maintenance more complex other than the initial conversion, please open an issue, we can consider disabling the rule. But the spelling check, will silently fail if the syntax is not correct and ignore the entire section where the syntax is not correct. It's important that we start running the syntax checks on all |
|
@TravisEz13 OK, I think I finally get the MD029 rule. While the procedure appears as step 1, step 1, step 1 in the MD file (which looks kinda borked), it actually shows up as step 1, step 2, step 3 in the rendered view. I was thinking that the rendered view would reflect the step 1, step 1, step 1 - which made no sense to me. :-) I updated the PR so it should pass the markdown pester tests now. P.S. I'd really like to get someone to review the |
|
@rkeithhill Thanks for the update! The ordered style is still used in two other places in |
|
Just saw that and pushed an update. One beef I have with VSCode is that it doesn't warn you when you commit a file that has unsaved changes. See microsoft/vscode#33004 |


Partially addresses #4894 and #4809.