Can’t find Visual Studio Command Prompt

I was working on a Windows Server 2012R2 machine. I had no idea where to find the Visual Studio command prompt. I used to work on a Windows Server 2016 machine. There it looks as follows:

In Windows Server 2012R2, the Start menu simply looks like this:

No idea how to get to the Visual Studio command prompt. No idea what to search for in the Search window. In the end I found a post where it’s explained how you can access the Visual Studio command prompt from within Visual Studio:

  1. Open VS 2017
  2. Go to Tools > External Tools…
  3. Click Add and enter the screen as below. The full path entered in the Arguments field is: “C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\Tools\VsDevCmd.bat”

From now on you will see a new option VS Command Prompt under the Tools menu in Visual Studio. Bang! It works again.

Debug Azure Functions

Since July I’m doing an assignment where Azure functions are intensively used. The functions are developed in Visual Studio, which has many advantages over developing functions in the Azure Portal. In Visual Studio you have intellisense, functions can be brought under source control and you can easily debug function execution. When you develop a Http Trigger function, you can perform the following steps:

  • Set Function project as the StartUp Project.
  • Set breakpoints in your function code.
  • Check if all application settings are contained in local.settings.json. When debugging the application settings from the Azure Portal are not used.

Example local.settings.json:
{
“IsEncrypted”: false,
“Values”: {
“APPINSIGHTS_INSTRUMENTATIONKEY”: “1ef50250-49f8-463d-849a-e264336c6797”,
“AzureWebJobsStorage”: “DefaultEndpointsProtocol=https;AccountName=…;AccountKey=…;EndpointSuffix=core.windows.net”,
“AzureWebJobsDashboard”: “DefaultEndpointsProtocol=https;AccountName=…;AccountKey=…;EndpointSuffix=core.windows.net”,
“AfasGetPos”: “https://99999.afasonlineconnector.nl/profitrestservices/connectors/ASB_Totara_Pos?take={0}”,
“AfasGetPosTake”: “1000”,
“AfasToken”: “PHRva2Vu…48L3Rva2VuPg==”
},
“ConnectionStrings”: {
“OutputDataConnectionString”: “Server=tcp:blo-asb-dev.database.windows.net,1433;Initial Catalog=db-blo-asb-dev-sql;Persist Security Info=False; …”
}
}

  • Press <F5> to start debug mode.

  • Copy the address from the debug Window that appears
  • Open Postman. Select POST as the Http method. Copy the function address in the address box. Enter the correct body and click submit.
  • The function will be called and the first breakpoint is hit in Visual Studio.

Following the above procedure, you can also debug a Queue trigger function. The only problem is, that you will not get an address after pressing <F5>.

That actually makes sense, because you are not calling a Http service. What you do after pressing <F5> is, drop a message in an Azure Storage queue via the Azure Storage Explorer. The function will be called again and the first breakpoint is hit in Visual Studio.

For remote debugging, see: TwoCents post.

Download App Content for Functions

It can come in handy to download functions from the Azure Portal. Click on your function app and click button [Download app content].

If the download is not activated, go to Settings / Advanced / Content Settings / Popups / Allow (in Google Chrome). A file will be downloaded without a file extension. Manually add .zip to the file name. Now you will have a zip file with the contents of your function app. In Visual Studio you will have a project template Azure Functions under Cloud. If not, check if Azure Functions and Web Job Tools is installed under Tools / Extensions and Updates.

Create an empty solution, add the downloaded project file with the functions.

  • Benefits of developing functions in Visual Studio:
  • Edit, build, and run functions on your local development computer.
  • Publish your Azure Functions project directly to Azure.
  • Use WebJobs attributes to declare function bindings directly in the C# code instead of maintaining a separate function.json for binding definitions.
  • Develop and deploy pre-compiled C# functions. Pre-complied functions provide a better cold-start performance than C# script-based functions.
  • Code your functions in C# while having all of the benefits of Visual Studio development.

Further information: docs.microsoft.com

Using Git

GIT is a decentralized version source control (DVCS) system where you work on a local repository that you can synchronize with a central repository so that other team members can use your code. A very useful branching model for Git is called GitFlow. This model is developed by Vincent Driessen and is targeted at making parallel development easy by using a master branch and a develop branch as a starting point. From the develop branch, you can make feature branches and release branches. From the master branch – which is production like always – you can create hotfix branches.

An excellent explanation of GitFlow can be found at: Explanation by Vincent Driessen

A very useful GIT client is SourceTree, which you can download for free via the following download link: SourceTree

There are also tools for easy Visual Studio integration.

A good explanation is provided here: Link

At the Visual Studio Market Place (Link) you can search for GIT. Here you’ll find:

  • Visual Studio Tools for Git (work with local Git repository)
  • GitHub Extension for Visual Studio (work with remote/central Git repository)

Deploy Logic App from Visual Studio

If you deploy a logic app from Visual Studio, you may run into problems. In this specific case I entered a WDL expression as the body of a Http Action:  @{decodeBase64(actionBody(‘GetDocument’)._buffer)}

After deploying the Logic App from Visual Studio, I looked at the Logic App in the Azure Portal. The code view looked OK, but in Design view the expression seemed to be replaced by actionBody(‘GetDocument’)._buffer. Strange.

If I look at the run details of the Logic App run, the input document is different:

Correct:
{
“uri”: “https://dspconnector.azurewebsites.net/api/AGA&#8221;,
“method”: “post”,
“body”: “…”
}

Incorrect:
{
“uri”: “https://dspconnector.azurewebsites.net/api/AGA&#8221;,
“method”: “query”,
“queries”: {
“document”: “…”

}

The solution of the problem is easy. Open the Logic App in the Azure Portal. In design view paste the code expression in the body of the http action, and voila, it works again. To keep the code in the Azure Portal and in Visual Studio consistent, you can – as a workaround – copy the code behind from the Azure Portal to Visual Studio. I couldn’t really tell the difference, but after doing that, Visual Studio Design View suddenly looked the same as the Azure Portal Design View. I could also successfully redeploy again. No idea what’s happening here.

Error when adding NuGet packages

You may run into an error when adding a NuGet package via the context menu of the References folder. The error I got, was: “Could not find a part of the path ‘C:\pb.bvgo-appservices\VW.Archibus.GatewayService\lib’”. I found out that this error can (for some strange reason) occur when your solution is added to TFS. The solution is to unbind your solution from TFS, add the NuGet packages and then rebind the solution. Go to: File -> Source Control -> Advanced -> Change Source Control to bind and unbind.

Add Visual Studio Command Prompt To Visual Studio 2015

I needed svcUtil to generate a client for a webservice. Problem: I couldn’t find the Visual Studio Command Prompt in Windows Server 2012 R2. Reason: you don’t have the classic start menu. After some looking around I found the following solution. Just add the Visual Studio command prompt as an external tool to Visual Studio 2015. Next type “svcutil /?” to check if you can access the tool.

To add Visual Studio Command Prompt:

  • Open Tools -> “External Tools…”
  • Click “Add”

Enter the following information into the new tool screen:

Field Value
Title Visual Studio Command Prompt
Command: C:\Windows\System32\cmd.exe
Arguments: /k “C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools\VsDevCmd.bat”
Initial Directory: $(SolutionDir)

Save your changes and the Visual Studio Command Prompt option will now be available in Visual Studio under tools.

Use Visual Studio to deploy Logic App

Some people prefer to use Visual Studio for all development purposes, also for Logic Apps. In Visual Studio 2013, Windows Azure SDK 2.6, a new project Azure Resource Group has been added. After clicking this project you can choose a template, for instance the Logic App template.

VS Project

VS Azure Templates

When you look at the project created, you will see a directory Scripts and a directory Templates. I have to check out the scripts directory, but I expect it to contain .ps1 files for deploying the resource(s). In the templates folder is a json file for your logic app.

VS Logic App Template

Note, there’s currently no visual designer for logic apps in Visual Studio. You can only build logic apps in JSON. When we zoom in to the template, you can see there are four main sections: parameters, variables, resources and outputs.

VS Logic App Template Zoom

When we open Resources we see a section labeled definition. Here is a default Logic App definition. We can change this definition to our needs, or we can throw away the definition and copy/paste the Json Logic App definition from the Azure Portal. Remember. When you design a Logic App via the Azure Portal, you can click in the Logic App Designer to go to code view. Here you find the json you need.

After changing the Logic App definition in the Json file, you can right-click the project and select Deploy. You get a page where you can set some config data. You can also add some parameters, for instance to set a specific name for the Logic App. See the screen shots below.

VS Deploy

VS Deploy Params

Now you have deployed a Logic App from Visual Studio.

Visual Studio tips

You can customize Visual Studio in a myriad of ways. In this post I want to mention two handy settings you can make use of. Go to Tools/Options.

First option makes sure that you always get the latest version on check out, so that you don’t overwrite code you didn’t get the last version of. Select Source Control, Visual Studio Team Foundation Server and check option Get latest version of item on check out.

Another handy option is that you select an item in the solution explorer when you have the tab with that item opened. In that way you can easily see where in the solution hierarchy the item is located. Go to Projects and Solutions, General and check option Track Active Item in Solution Explorer.