다음을 통해 공유


Nano Server Developer Experience - Visual Studio 2015 Update 1 and above

This blog post is now obsolete. Please go to the new blog post here: https://blogs.technet.com/b/nanoserver/archive/2016/04/27/developing-native-apps-on-nano-server.aspx

Nano Server represents a great opportunity for applications to get the most of available resources and deliver customers an agile environment which supports a DevOps management model. In order for applications to do this, they need to remove references to components not delivered in Nano Server (this typically means APIs which bring in the GUI or 32 bit references).

To make developing and porting apps to Nano Server easy, we added “decorations” to the Windows header files to include the right APIs, and created a Visual Studio template which leverages this header decoration work, and automates the inclusion of the right headers and libraries. You can enjoy full IntelliSense and error squiggles support.

Thanks to the Visual Studio Debugger team, the Nano Server developer experience includes full remote debugging from Visual Studio!

To automate some of the mundane tasks, we also included a small PowerShell module to make it easy to install the debugger binaries on the Nano Server machine, as well as start & stop the debugger.

Prerequisites

  1. On your development machine, you should be running the latest version of PowerShell, i.e. Windows 10, a preview release of Windows Server 2016, or the latest version of the Windows Management Framework.

  2. Make sure your development machine is running Hyper-V, if you’re going to run Nano Server in a VM. Otherwise, make sure that your development machine has network access to your Nano Server machine.

  3. Install the Update 1 version of Visual Studio 2015. Here’s a link to download the free community version of Visual Studio. Make sure to choose “Custom” install, and under “Universal Windows App Development Tools”, ensure that “Tools (1.2) and Windows 10 SDK” is checked.

  4. Download the zip file attached to this blog and unzip it:Follow the instructions in Getting Started with Nano Server to build your Nano Server VHD using New-NanoServerImage, and then use it to boot on a physical machine or in a VM.

    1. Double-click on NanoServerProjectExtensions.vsix and follow instructions to install it.
    2. Import the PowerShell module (NanoServerDebugger.psm1) by opening an elevated PowerShell or ISE session, use Import-Module and pass the full path to the .psm1 file. Don’t close the PowerShell session! If you do, you would have to import the module every time you open the PowerShell session (unless you use a PowerShell profile of course J).

Writing your First App

Now you’re ready to develop your first Nano Server app. Let’s write and debug a simple app.

  1. Create a new project and, under Visual C++, choose “NanoServerApplication”. Call your project “NanoApp1”.

  2. In the debug target drop down, select x64 as the target platform

  3. In the Project Properties dialog, under “General”, make sure that the “Target Platform Version” is 10 (typically 10 point something).

  4. In Solution Explorer, double-click on NanoServerApplication.cpp. In _tmain, add printf(“Hello from Nano Server!\n”); Press Ctrl+F5 to make sure everything works locally.

  5. From an elevated PowerShell or ISE console (import the PowerShell module again if you closed the previous console), create a session to the Nano Server machine or VM, using the following commands (for more information, consult the Nano Server Getting Started guide):

    1. $ip = “ip address to the Nano Server machine
    2. Ensure that TrustedHosts is set to the Nano Server IP address. Otherwise: Set-Item wsman:\localhost\client\TrustedHosts “ip address to the Nano Server machine
    3. $s = New-PSSession –ComputerName $ip –Credential ~\Administrator
    4. Install-NanoServerDebugger –session $s
  6. Copy the .exe and the .pdb files from the app you just wrote to Nano Server, using the same session object:

    1. Enter-PSSession $s
    2. Md c:\NanoApp1 # for example
    3. Exit-PSSession
    4. Copy-Item –ToSession $s –path “path to the .exe and .pdb files” –Destination c:\NanoApp1. Remember to do this every time you build a new .exe! (Alternatively, you can refer to the local pdb file, but make sure to change the project properties to reflect that).
  7. In the project properties dialog, under Configuration Properties \ Debugging:In the open PowerShell console, start the debugger using Start-NanoServerDebugger –Session $s

    1. Change the “Debugger to launch” to: “Remote Windows Debugger”. 
    2. Remote Command = C:\NanoApp1\NanoApp1.exe (full path to the Nano app executable)
    3. Working Directory = C:\NanoApp1 (path to the Nano app executable folder)
    4. Remote Server Name = IP address of the Nano Server machine
    5. Connection = “Remote with no authentication”
  8. Now you’re ready to debug your app. Set a breakpoint and press F5 and you’re good to go! Use locals, watches … pretty much everything you’re used to using in a debugging session.

  9. To stop the debugger, use: Stop-NanoServerDebugger –Session $s         

 Now that our simple app is working, try your hand at a WMI provider, such as this MI API sample (which also creates a PowerShell cmdlet along with the provider), or Querying a Service's Configuration.

 At any rate, you’ll want to make sure that your application can participate in a DevOps management model. This entails two things:

  1. Ensure your application can be fully configured using PowerShell Desired State Configuration (DSC). Writing a DSC provider ensures that customers can choose the DevOps deployment tool of their choice and ensure that your application will “just work”. (Note that DSC is now available on Nano Server starting with Technical Preview 4)
  2. Ensure your application can be fully managed remotely via PowerShell. You can write PowerShell cmdlets in native code using a WMI V2 provider, in managed code using .NET Core, or in PowerShell itself.

 Please use the Nano Server forum to ask questions. We look forward to your feedback. 

Happy coding :)

 

ref@

Comments

  • Anonymous
    December 23, 2015
    [If you're using Visual Studio 2015 Update 1 or above, please go to the new Developer Experience
  • Anonymous
    December 25, 2015
    I think all these lines in the provided module:

    Write-Host $Error_VSnotInstalled
    Write-host $Error_WMF5_Win10
    Write-host $Error_InvalidSession
    $Error_WrongVSVersion

    should use Write-Error . Write-Host cmdlet is not the best one to output error messages.
  • Anonymous
    January 01, 2016
    We have a preliminary doc for getting ASP.NET 5 running on Nano Server in a non-container scenario. Feedback on the document is greatly appreciated!

    https://github.com/aspnet/Docs/issues/194#issuecomment-168304716
  • Anonymous
    January 21, 2016
    As organizations move toward modern DevOps practices, the role of the operating system needs to evolve
  • Anonymous
    March 17, 2016
    Hi, I'm trying to use this on a nano server deployed in Azure and I'm wondering what ports I need to open. I tried with ports TCP 135,139,445, 137, 138 as described in this article (https://msdn.microsoft.com/library/ee126350(v=vs.100).aspx) does this solution require the same ports?
  • Anonymous
    April 18, 2016
    I'm having trouble getting a managed C++ application to compile. Is managed C++ still supported on NanoServer?