20

I know there have been other references to this issue. But I didn't upgrade from one version of VS to another. I am currently using VS 2013. The project builds fine, and has even deployed successfully in the past. This is a brand new app. So it wasn't something inherited from another project. Where can I start looking? What can I post here that may be helpful for you guys to hopefully help me? It is a web api 2 site. I am using the publish command within VS2013.

Greg P
  • 772
  • 2
  • 10
  • 23
  • possible duplicate of [Where is MsDeployPublish located?](http://stackoverflow.com/questions/19295854/where-is-msdeploypublish-located) – Robert MacLean Dec 23 '14 at 11:49

12 Answers12

41

Adding the lines below to my .csproj file seems to solve the same error for me:

<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>

As part of trying to resolve the issue, I've also installed the MSBuild.Microsoft.VisualStudio.Web.targets Nuget Package. But I'm still not sure it was necessary in order to resolve the issue.

RonyK
  • 2,644
  • 5
  • 32
  • 42
  • 4
    I did not need MSBuild.Microsoft.VisualStudio.Web.targets to be installed, because its already on target machine, but yes i did need change csproj to include: VSToolsPath as above and – Gatis Bergšpics Aug 19 '14 at 12:34
  • 2
    The 3 import lines after this `PropertyGroup` are also required or you will get the error described in the title as well. http://i.imgur.com/7H6JP20.png – Rush Frisby Feb 02 '15 at 15:33
  • 5
    For me, installing the MSBuild.Microsoft.VisualStudio.Web.targets package seemed to fix my issue. I also installed Microsoft.Web.WebJobs.Publish but not sure if that factored into the fix. – cr1pto Jun 06 '16 at 19:17
  • 4
    Reinstalling Microsoft.Web.WebJobs.Publish helped to solve this issue. – ohavryl Sep 23 '16 at 10:02
  • 3
    I did not need to add these lines to my .csproj. The import line was already here. Installing the MSBuild.Microsoft.VisualStudio.Web.targets Nuget package solved the problem. – Pierrick Martellière Jul 08 '17 at 15:51
  • Removing and Reinstalling Microsoft.Web.WebJobs.Publish did it for me – donquijote Sep 06 '17 at 11:49
38

If you get this MSB4057 error from a WebJob project using "Publish as Azure WebJob" using Visual Studio 2013/update 4 - you may need to update the NuGet package Microsoft.Web.WebJobs.Publish

Check MyWebJob\packages.config and if the version is 1.0 you need version 1.02 or higher. From the package manager console run

 Install-Package Microsoft.Web.WebJobs.Publish -Version 1.0.2
RickAndMSFT
  • 20,912
  • 8
  • 60
  • 78
  • 2
    This doesn't solve it for me. I am publishing a plan webjob (console app) to an Azure web site and receive the error. – Tim Gabrhel Mar 22 '15 at 02:43
  • 1
    Create another solution with a console app, deploy to azure - then diff the two .csproj files. – RickAndMSFT Mar 23 '15 at 04:17
  • Thanks. Ultimately, the csproj was indeed modified by another job I created. It appears the csproj modification may have failed (but the package installed) leaving the issue initially. – Tim Gabrhel Mar 25 '15 at 00:24
  • 1
    Yep, the install.ps1 throws an error when installing that package (possibly if you're not running VS2015 with admin rights) - see here for a possible fix: http://stackoverflow.com/a/32330491/119761 – keithl8041 Sep 01 '15 at 11:32
  • 1
    Running VS 2015 Community Update 1 Microsoft ASP.NET and Web Tools 14.1.20203.0 extension, I didn't need to run in admin mode or modify the csproj file to resolve this issue. The aforementioned NuGet package, `Microsoft.Web.WebJobs.Publish` was all I needed. Thanks! – Vinney Kelly Feb 12 '16 at 21:46
  • `Update-Package –reinstall "Microsoft.Web.WebJobs.Publish"` worked for me. This error started when I had moved the solution file ... and packages were no longer in the expected place. Specifically: `` – Matthew Sep 30 '16 at 12:10
  • This did it for me as well. – GETah Nov 13 '16 at 10:44
  • Had this Issue in VS 2017, solved it by updating the package. thanks – Michael Staples Jan 24 '19 at 13:24
  • Updating from 1.0.13 to 2.0.0 solved it for me (VS2019) – RuudvK Mar 10 '21 at 12:12
11

With VS 2013 Update 4. There seems to be issues with the template of a Webjob project so that the reference to webjobs.targets is wrong, even though you've installed the Microsoft.Web.WebJobs.Publish package.

Make sure There Import statement at the bottom of of the project is correct in terms of the path, I tested twice and found it was malformed.

<Import Project="..\..\packages\Microsoft.Web.WebJobs.Publish.1.0.2\tools\webjobs.targets" Condition="Exists('..\..\packages\Microsoft.Web.WebJobs.Publish.1.0.2\tools\webjobs.targets')" /> 

Also, better avoid using the below, since it binds you to a specific VS version.

<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
Uri Golani
  • 111
  • 1
  • 2
  • So I am on vs2013 update 5. My paths etc are all correct my version is 1.0.2 but i still get this issue. Any ideas? – Ismail Jun 16 '16 at 16:54
  • This should be the solution! Adding the import line (though with version 1.0.11) worked for me. Thank you! – Sam Oct 14 '16 at 06:41
11

FYI, same issue on VS2019, same solution:

  • Install the nuget Microsoft.Web.WebJobs.Publish
  • Install the nuget MSBuild.Microsoft.VisualStudio.Web.targets
avs099
  • 10,937
  • 6
  • 60
  • 110
Bart Coppens
  • 178
  • 1
  • 7
  • 1
    Dido, as of Nov 2019, just install `Microsoft.Web.WebJobs.Publish` (currently 2.0), BUT I didn't have to do step two. For some reason, I've been publishing this webjob without problem for years, but suddenly it needed this package, which never had been installed before. – Nicholas Petersen Nov 25 '19 at 16:46
4

For those who are deploying a WebJob, this error might also be due to a missing webjob-publish-settings.json file (it should be located in the Properties folder of the WebJob project). Its structure should be e.g:

{
  "$schema": "http://schemastore.org/schemas/json/webjob-publish-settings.json",
  "webJobName": "MyWebJob",
  "startTime": "2017-01-27T03:00:00+00:00",
  "endTime": null,
  "jobRecurrenceFrequency": "Hour",
  "interval": 1,
  "runMode": "Scheduled",
  "is_singleton": true
}

(this is for an hourly scheduled job).

McBodge
  • 81
  • 8
3

Having just re-installed VS 2017 (15.5.6) I ran into this with one of three WCF projects. I picked through the csprojs for all three and could find no difference between them, cutting and pasting the various imports, paths etc from the working ones didn't make any difference.

Adding the nuget package MSBuild.Microsoft.VisualStudio.Web.targets (v14.0.0.3 was the latest, i.e. VS2015) has fixed the problem...for the moment. I can't believe this has gone away for good though.

Mike Dean
  • 67
  • 1
  • 3
2

Just bumped into this exact error with VS 2015 Update 3. The latest Microsoft.Web.WebJobs.Publish was installed, and I tried unstalling and re-installing for good measure. Still didn't work but there was an error on install that I didn't see the first time around:

install.ps1 cannot be loaded because running scripts is disabled on this system.

This is something that most who have ever run a PowerShell script have run into at one time or another and easy to fix (solution is here), but the error message itself is easy to miss.

Community
  • 1
  • 1
Todd Menier
  • 37,557
  • 17
  • 150
  • 173
1

Just run the below on the project you want to publish ( and make sure your VisualStudio is running as "Administrator" )

install-package Microsoft.Web.WebJobs.Publish
Illuminati
  • 4,539
  • 2
  • 35
  • 55
0

In order to fix the issue for Visual Studio Enterprise 2015 Update 3, I had to install the following packages and edit the Web job's project file as follows.

STEP 01:Install Packages(Run VS as Administrator for script execution)

1. install-package **MSBuild.Microsoft.VisualStudio.Web.targets**

2. install-package **Microsoft.Web.WebJobs.Publish -Version 1.0.2**

STEP 02: Edit WebJob Project File(Unload the project from VS and Edit/Save .csproj then reload)

 <PropertyGroup>
    <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
    <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
marvelTracker
  • 4,691
  • 3
  • 37
  • 49
0

I got this error in a project with a project.json for the nuget packages.

When I removed the project.json and used the packages.config everything worked fine.

Mind that I did set the ExecutionPolicy for Windows PowerShell before I tried this, (see solution of @Jon Crowell), this might be necesary too.

If anybody finds a way to solve this with a project.json please let me know!

Community
  • 1
  • 1
Marcel Wolterbeek
  • 3,367
  • 36
  • 48
0

I hit this same problem with a project loaded in Visual Studio 2017. It was previously working on a different machine, but not when I migrated to a new one.

After trying all of the suggestions in the answers here (the question is somewhat duplicated several times on StackOverflow), I finally ran across someone elsewhere who mentioned installing the Azure SDK for VS2015.

This isn't supposed to be needed for VS2017, but it solved the problem for me. I'd previously used 2015 on my old machine but had switched to 2017. Apparently, the SDK bits still mattered.

Will
  • 425
  • 4
  • 8
0

To add to the answer by @Uri Golani, a switch to the new PackageReference way instead of with the traditional nuget that uses the packages folder, meant it looked like I could delete the packages folder. Whelp, apparently, those references in the csproj to the packages folder (which folder I had deleted) were the problem. I'm not sure how to get the right reference to something else (whatever cache the PackageReferences refer to), so for now, just re-adding a packages folder, with the Microsoft.Bcl.Build.1.0.21 and the Microsoft.Web.WebJobs.Publish.1.1.0 nuget folders seemed to fix this.

Nicholas Petersen
  • 9,104
  • 7
  • 59
  • 69