Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to debug and publish Azure Function from Visual Studio 2017

I used to debug and publish my Azure Function Project using Visual Studio 2017.

However suddenly everything stopped working.

When i tried to debug the project i got the error "A project with an Output Type of Class Library cannot be started directly.". When i tried to publish the project, the option to publish to Azure disappeared and i'm only offered to publish to a folder. When trying to create a profile i can also only choose the Folder Profile type.

I saw a similar behavior once in a Web Project when the "Project Sdk" Attribute in the .csproj file was wrong but i doublechecked it with a newly created Azure Function Project and it was the same. When i create a new function project, i can publish to Azure as i could before.

I'm using the following packages:

along with .NET Framework 4.7.1.

Also i'm referencing some other projects from my solution containing Business Logic.

I ended up creating a new function project, copying everything there and now it's working again as expected.

Does anybody know how this could happen and how to fix it without creating everything from scratch?

like image 652
Markus Strobl Avatar asked Feb 20 '18 08:02

Markus Strobl


People also ask

How do I publish a Visual Studio Azure function?

Use the following steps to publish your project to a function app in Azure. In Solution Explorer, right-click the project and select Publish. In Target, select Azure then Next. Select Azure Function App (Windows) for the Specific target, which creates a function app that runs on Windows, and then select Next.

How do I redeploy Azure function in Visual Studio?

Redeploy your function app with new APIs to AzureSelect your function app from the list of apps. Select Deploy from the pop-up window. Wait until the deployment completes.


Video Answer


2 Answers

In my case I was able to fix it by ensuring the NuGet package for Azure Functions was referenced:

<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.14" />    
like image 101
Ben H Avatar answered Oct 25 '22 22:10

Ben H


I just had this same thing happen to me. I added a new Azure Function project to an existing solution, and it wouldn't let me debug it. I added an additional Azure Function project just to test it, and it worked fine. Compared the .csproj files, they were both correct.

I restarted Visual Studio and I was able to debug both Function projects, though I don't know if that will always fix the problem.

like image 27
mdickin Avatar answered Oct 25 '22 21:10

mdickin