Markus S.
Markus S.

Reputation: 2812

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?

Upvotes: 18

Views: 6331

Answers (6)

Edgar Garcia
Edgar Garcia

Reputation: 1

Just Reinstall Azure Functions Core Tools, sometimes it's self installed by restarting VS

Upvotes: 0

Garnovski
Garnovski

Reputation: 3

It could be because the wrong project is set as startup project. In the solution explorer, you'll notice that the startup project is in bold. If it is not the right project, try right clicking on the correct one and click Set as startup project.

Solved it for me.

Upvotes: 0

Ben H
Ben H

Reputation: 3236

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" />    

Upvotes: 18

peterfelts
peterfelts

Reputation: 552

I had the same problem. I went in to the Visual Studio Installer and (re?) installed the "Azure development" workload. That fixed it for me.

Upvotes: 4

mdickin
mdickin

Reputation: 2385

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.

Upvotes: 10

rasmusgude
rasmusgude

Reputation: 489

Azure Functions tooling for Visual Studio is not always as stable as one would wish - but it's getting better for every release.

I had a similar problem after updating to Visual Studio 2017 v15.3 and then again when updating to v15.5. Both problems disappeared after updating or reinstalling the Azure Functions plugin.

But if you already have opened (and saved) to solution with a non-working VS setup then VS seems to 'destroy' the project sometimes.

You could look in your non-working project to see if your .csproj-file(s) contain:

<ProjectGuid>{0EC16A67-C60A-4950-A533-07D8783C88B0}</ProjectGuid>

...which is the guid for Azure Functions projects. If your ProjectGuid is different then you could try changing it to the above and it should(might?) work.

Upvotes: 0

Related Questions