Skip to content

Conversation

@anmenaga
Copy link

@anmenaga anmenaga commented Oct 12, 2017

Adding PowerShell/docs/cmdlet-example/README.md that describes how to create a .net core cmdlet with Visual Studio.

Fix #3081
Fix #4809

@anmenaga anmenaga requested a review from SteveL-MSFT October 12, 2017 19:37
@anmenaga
Copy link
Author

Review shows urls instead of images;
Here is how it looks like with the images:
https://github.com/anmenaga/PowerShell/blob/CmdletExample/docs/cmdlet-example/README.md


This demonstrates how to build your own C# cmdlet for PowerShell Core with Visual Studio.

We will use free Visual Studio Community 2017 that can be downloaded from [https://www.visualstudio.com/downloads](https://www.visualstudio.com/downloads)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can just make 'Visual Studio Community 2017' the link instead of making the hyperlink text the hyperlink

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

1. When installing Visual Studio 2017 select `.NET Core cross-platform development` under `Other Toolsets`
![1](https://user-images.githubusercontent.com/11860095/31471799-7ca192f4-ae9f-11e7-9731-03fb24ba949c.png)

2. Create new C# project `SendGreeting` of type `Class Library (.NET Core)`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the markdown rules are to use 1. for each item in the numbered list and the renderer takes care of incrementing

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've checked - both syntaxes can be used.
Tried to use '1.' for all items, but got across formatting issues and number list getting broken after code section. Not worth the time spent on changing this.

We will use free Visual Studio Community 2017 that can be downloaded from [https://www.visualstudio.com/downloads](https://www.visualstudio.com/downloads)

1. When installing Visual Studio 2017 select `.NET Core cross-platform development` under `Other Toolsets`
![1](https://user-images.githubusercontent.com/11860095/31471799-7ca192f4-ae9f-11e7-9731-03fb24ba949c.png)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These images should have proper file names and checked into this folder so it's self contained

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ironically, I was specifically trying to avoid that. :)
Updated.

5. Build solution (F6); The `Output` window will print the location of generated cmdlet DLL:
![6](https://user-images.githubusercontent.com/11860095/31471804-7d1a66f2-ae9f-11e7-93c2-df72fb43da81.png)

6. Start PowerShell Core, run `Import-Module` on DLL path from previous step and run cmdlet:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should show that this cmdlet should also work with Windows PowerShell v3+ (although I believe we have a problem right now with .Net Std shims now being available for .Net 4.6.x)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like you said, right now its not working.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update: it actually does work with .Net 4.7.1 on WindowsPS on Win10, but some instructions have to be different for cmdlet built for PowerShell Standard.

@SteveL-MSFT
Copy link
Member

@anmenaga updated your description, I believe this should also address #4809

In `Solution Explorer` right click on project `Dependencies` and select `Manage NuGet Packages...`
In the top-right corner of the package manager click on the small `Settings` sprocket icon that is to the right from `Package source` dropdown.
By default, there will be only `nuget.org` package source in `Available package sources` list.
Add another package source with name `powershell-core` and source `https://powershell.myget.org/F/powershell-core/api/v3/index.json`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For issue #4809, you need to use the package PowerShellStandard.Library instead.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already updated. :)
Added a separate list of steps for PowerShell Standard.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, thanks.

@daxian-dbw
Copy link
Member

daxian-dbw commented Oct 18, 2017

Please add this file to the docsToTest list in markdown.tests.ps1, so that the test can validate the markdown syntax of this file.

The .spelling file needs to be updated. Please see the failure in Travis-CI build.

@@ -0,0 +1,118 @@
# Building a C# Cmdlet for PowerShell Core
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to say "with Visual Studio 2017", to differentiate from #5117

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

@@ -0,0 +1,118 @@
# Building a C# Cmdlet for PowerShell Core

This demonstrates how to build your own C# cmdlet for PowerShell Core with Visual Studio.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't use README.md, instead use a file name like visual-studio-simple-example.md.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

renamed


This demonstrates how to build your own C# cmdlet for PowerShell Core with Visual Studio.

We will use free [Visual Studio Community 2017](https://www.visualstudio.com/downloads).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use free

Maybe use the free?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

![Step8](./Images/Step8.png)


# Building a C# Cmdlet for PowerShell Standard 3.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You cannot have 2 top-level titles in one markdown file. The markdown test will report an error on this. So you need to re-organize the hierarchy of the content.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed by adding 1 master TOC-type section in the start of the doc with links to 2 subsections.

@anmenaga
Copy link
Author

Added this doc to markdown.tests.ps1; tests pass.
.spelling file updated.

@anmenaga
Copy link
Author

By default, there will be only `nuget.org` package source in `Available package sources` list.
Add another package source with name `powershell-core` and source `https://powershell.myget.org/F/powershell-core/api/v3/index.json`
![Step3](./Images/Step3.png)
In the package manager select new `powershell-core` in `Package source` dropdown, select `Browse` tab, type in `System.Management.Automation` in the search and select `Include prerelease`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is rendered to the same line of the image. Should be in a new line.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

1. Create new C# project `SendGreetingStd` of type `Class Library (.NET Standard)`
![StdImage21](./Images/Std21.png)
On project properties verify that `Target framework` is `.NET Standard 2.0`:
![StdImage22](./Images/Std22.png)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This image is rendered to the same line as the above text. Should be in new line.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

![StdImage5](./Images/Std5.png)

1. Now cmdlet can be run on systems supported by PowerShell Standard; for example:
On PowerShell Core on Windows:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this line supposed to be on a newline? It's rendered in the same line as above text.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.


## Building a C# Cmdlet for PowerShell Core with Visual Studio

This demonstrates how to build your own C# cmdlet for PowerShell Core with Visual Studio.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's worth explicitly saying something like:

Targeting for PowerShell Core means that the cmdlet may not work against Windows PowerShell if you take dependencies on new APIs introduced in PowerShell Core.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point; updated.


## Building a C# Cmdlet for PowerShell Standard 3.0 with Visual Studio

Steps below show how to build your own C# cmdlet for PowerShell Standard 3.0 with Visual Studio.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's worth adding explicitly:

Targeting PowerShell Standard 3.0 means that the same module will work against PowerShell Core as well as Windows PowerShell v3 and newer, however, you are limited to a subset of the available PowerShell APIs.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

@anmenaga
Copy link
Author

@daxian-dbw daxian-dbw merged commit e0af4d9 into PowerShell:master Oct 23, 2017
@anmenaga anmenaga deleted the CmdletExample branch October 31, 2018 21:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants