84

I have recently installed the new Azure development tools for Visual Studio 2010 service pack 1. Every time that I try to publish an existing website (using file system deployment) I get the following error:

The target "GatherAllFilesToPublish" does not exist in the project.

Can anyone tell me what I am missing?

Thanks

Roman Marusyk
  • 23,328
  • 24
  • 73
  • 116
Joe
  • 1,129
  • 1
  • 7
  • 16

19 Answers19

85

I think that I know what the issue is. When you install the Azure SDK bits it installs some VS Web Publish updates. One of these updates the file at

C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets

Based on how our setup is defined if that file has an updated timestamp (for whatever reason) then when you install the new component the file does not get updated.

To resolve this you should be able to follow the steps below:

Syntle
  • 5,168
  • 3
  • 13
  • 34
Sayed Ibrahim Hashimi
  • 43,864
  • 17
  • 144
  • 178
  • 1
    As Sprinkle said, the files are located in v10.0 folder but did the trick! Thanks! – Zenuka Jul 10 '12 at 12:17
  • 2
    I didn't change Microsoft.WebApplication.targets but the HotFix worked for me. – Brian Nov 09 '12 at 16:27
  • 4
    Worked for me after I applied the hotfix, closed Visual Studio and reopen it again to take effect. – Jeff Dec 11 '12 at 01:57
  • Worked for me! After installing the update two new elements - - were added, plus an . When these are missing from Microsoft.WebApplication.targets you'll need the update. – Frank van Eykelen Feb 05 '13 at 16:25
  • Worked for me as well - also required a reboot per Jeff's comment. – James Fleming Mar 18 '13 at 11:25
  • This worked for me too. I had VS2013 installed and was getting this error in VS2010. – GL_monk-342435 Oct 21 '14 at 20:26
  • 1
    The unfortunate thing is that this answer has taken over the search results for this error even though it *only* applies to vs 2010 - is there a solution for other versions of VS? – George Mauer Aug 14 '15 at 15:37
  • 3
    for me even after closing VS will say KB2591016 does not apply, or is blocked by another condition on your computer – Iman Apr 23 '17 at 11:47
79

I had this problem, and it was fixed by adding:

<Target Name="GatherAllFilesToPublish">
</Target>

to the Project File.

Emanuele Ciriachi
  • 2,216
  • 2
  • 26
  • 39
  • 1
    This worked for me but creates an additional folder called Backup and backs up the file to it. Damn VS 2013 is buggy – PhillyNJ Feb 19 '14 at 22:23
  • 1
    This fixed the issue for me in VS2013. Don't see any extra Backup folder mentioned by @PhilVallone – Alexander Puchkov Jul 03 '14 at 18:55
  • 6
    I tried that. The error disappeared but all the .cs files got published too. I reckon this is because you only add a stub. This answer is not a fix for the root issue, it is a workaround. – chiccodoro Mar 03 '15 at 13:12
  • 2
    Worked for me. Ensure that when you add the target it should not be commented. – kulNinja Oct 11 '15 at 22:48
  • 1
    This is not a fix, as it adds basically all files in the project folder to your to-be-published package. Including files you don't want to have laying around on the server. – derFunk Dec 16 '15 at 19:22
  • 2
    this fixed the problem for me as well. Just so that everyone understand, to implement this you need to right-click on the project (not solution) in Visual Studio, select "Unload Project", then right click on it again and select "Edit ", then past this into the file and save it, Close the file, then right-click on it again and select "Reload Project". Then test your Publish again and see if it works – mknopf Feb 01 '19 at 15:57
  • I tried this and the project then built but no files were being published to the publish directory. One of the responses here suggests that this is a result of having this: https://stackoverflow.com/questions/18779518/could-not-load-file-or-assembly-oracle-dataaccess-or-one-of-its-dependencies so it was not a fix for me. – WillC Nov 06 '19 at 16:37
  • It works for me like a sharm! – Luis Armando May 31 '22 at 18:29
47

This worked for me fix - gather all files to publish error

  1. Right click the project and select Edit (project name).csproj. (e.g. Edit in notepad)
  2. Look for <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
  3. Add the following above the line.

    <PropertyGroup> 
     <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">13.0</VisualStudioVersion>
     <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
    </PropertyGroup>
    
  4. Save and Reload project.

PhillyNJ
  • 3,859
  • 4
  • 38
  • 64
15

I ran into this issue with VS 2017 and I tried manually changing the csproj file as suggested here and none of the suggested fixes worked for me. I ran across this nuget package. Installing it worked for me.

MSBuild.Microsoft.VisualStudio.Web.targets

Buddy J
  • 263
  • 3
  • 9
  • Thank you so much! This worked for me. And I thought it was going to be one of THOSE days. – Timothy Kanski Dec 14 '18 at 15:23
  • Thank you! The suggestion above that says to add the Target node to the project file includes way too many files and I agree with the comments about it being a workaround, not a solution. This seems to publish exactly as expected after installing this Nuget package. Thanks again! – zpert Oct 05 '20 at 17:59
  • Perfect!! Thank you for this. It worked for me I could see in my csproj file that it was pointing to a location v10.0 that does not exist I installed the package and was then able to publish. – cormacio100 Aug 23 '22 at 19:00
10

Same problem with VS2017. You can try this, it worked for me.

  1. Unload the project and Edit csproj file
  2. search the keyword "WebApplication.targets"

     <Import Project="...\WebApplications\Microsoft.WebApplication.targets" ... >
    

    COMMENT or REMOVE this line.(maybe two lines depending on "Condition")

  3. Save and Reload project

In this step, it will prompt you to install some package about 500M...

After that, reload project, then it works!

I guess I just miss some components when I install VS 2017.

Also I notice the MSBuild Path is quite different in VS2017, but maybe that's not related to the problem cuz it uses relative path in the csproj file..

Joey
  • 109
  • 1
  • 4
9

Removing these installations solved the issue for me:

  • Microsoft Web Publish - Visual Web Developer Express 2010
  • Microsoft Web Publish - Visual Studio 2010

Reference

Eduardo Campañó
  • 6,778
  • 4
  • 27
  • 24
5

I had similar issue when I wanted to publish my ASP.Net application to Windows Azure. After many trial and error finally this solution worked for me. This does not need any renaming of files or any installation / reinstallation of hotfixes / patches. Here is what you have to do:

Open the ASP.Net project file (.csproj) in Wordpad / Notepad and find the line looking similar to this:

<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" Condition="'$(Solutions.VSVersion)' == '8.0'" />

Replace it with line as given below:

<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
Rashid
  • 51
  • 1
  • 2
  • Please, try to read this http://stackoverflow.com/help/deleted-answers, to get more understanding how to **not** answer. Namely: "Answers that do not fundamentally answer the question": **barely more than a link to an external site** – Radim Köhler Sep 26 '13 at 05:06
  • 1
    You saved my day! I tried all the other answers and none worked out. It turned out that in my csproj file, for whatever reason, the line even contained the attribute in the literal form of `Conditon="false"`. I also had to clean & rebuild the project before it started working. – chiccodoro Mar 03 '15 at 13:17
4

I realize this in an old question, but I ran into it recently and here is how I solved it.

Background: I had an old project that I upgraded to VS studio 13. It looks like the project file wasn't upgraded properly.

There are references to VS v10.0, in the csproj file, but I am running VS 13 which is really "v12.0".

So I told the csproj file to use the "v12.0" folder, not a "v10.0" folder.

This is what I had:

<PropertyGroup>
  <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
  <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\..\BuildTools\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" />
<Import Project="$(SolutionDir)\..\BuildTools\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" Condition="false" />

This is what I changed it into:

<PropertyGroup>
  <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">12.0</VisualStudioVersion>
  <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" />

Now my publishing to the filesystem works!

Vilhelm H.
  • 1,315
  • 1
  • 7
  • 15
4

I had the same issue: I created the project in VS 2010, and had to publish from VS 2019. None of the solutions here worked for me, and I'd been with the issue for about a day.

What did work came from this link: http://www.dotnetxp.com/visual-studio-error-publish-target-gatherallfilestopublish-not-exist-project/

This is what I did:

** Unloaded offending project.

** Open csproj file in text editor.

** Find this line

<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />

and replace with this. I use 16.0 because that's the version I'm using (vs2019).

<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">16.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v16.0\WebApplications\Microsoft.WebApplication.targets" Condition="false" />

** Reload project and publish.

Worked like a charm.

fdkgfosfskjdlsjdlkfsf
  • 3,165
  • 2
  • 43
  • 110
3

I had a similar issue and resolved it by using the steps provided by Sayed.

The file I renamed was in the v10.0 directory though.

C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets.

The original file that was there was dated 18-Jan-2011, after renaming it with a .bak extensions then reinstalled KB2591016, publishing seems to be working again. The new date of the file Microsoft.WebApplication.targets is now 11-Aug-2011.

Praveenkumar
  • 24,084
  • 23
  • 95
  • 173
Sprinkle
  • 31
  • 1
3

I've been struggling with the same problem with Visual Studio 2013 (and 2015).

The crucial fix for me was to add the VSToolsPath property setting, which was missing in my project file, for whatever reason.

I added this into the <PropertyGroup> directive:

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

As a side note: My project file is also referencing the v10.0 version of the Microsoft.WebApplication.targets file, but that seems to be okay.

derFunk
  • 1,587
  • 2
  • 20
  • 31
2

I had the same error. Somehow this line was missing.

<Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" />

Added it just below

<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

Works fine now

StefanHa
  • 727
  • 8
  • 19
2

I have the same issue in VS2013, the solution I found was by creating a new empty web application project can copying the following lines from it into my old website project: At the top:

<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />

<PropertyGroup>
    <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
    <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
  </PropertyGroup>
  <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
  <Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" />
  <Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" Condition="false" />
learnerplates
  • 4,257
  • 5
  • 33
  • 42
2

Right click the project and select Edit (project name).csproj. (e.g. Edit in notepad) Look for Add the following above the line.

13.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) Save and Reload project.

This really work for me, Thanks

Pratham
  • 71
  • 3
2

For Visual Studio 2017 - it should be added after the block in the .csproj file, use notepad and look for ".targets" to locate it...

I created a new VS 2017 project and this is working for me (with no warnings):

  <PropertyGroup>
    <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
    <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
  </PropertyGroup>
  <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
  <Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" />
  <Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" Condition="false" />
  <Target Name="MvcBuildViews" AfterTargets="AfterBuild" Condition="'$(MvcBuildViews)'=='true'">
    <AspNetCompiler VirtualPath="temp" PhysicalPath="$(WebProjectOutputDir)" />
  </Target>
Yovav
  • 2,557
  • 2
  • 32
  • 53
1

Sayed's solution did not work in my project which was upgraded using VS2012. But this worked

Rush Frisby
  • 11,388
  • 19
  • 63
  • 83
1

If editing in VS2012 (Visual Studio 2012) a VS2010 project try this. Edit the csproj file from:

<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />

And change to:

<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v11.0\WebApplications\Microsoft.WebApplication.targets" />
SushiGuy
  • 1,573
  • 17
  • 20
0

Since the issue cannot be reproduced on my side, I would like to suggest you to try to reinstall the SDK.

Please try to remove the old SDK completely before installing the new one.

Best Regards,

Ming Xu.

Ming Xu - MSFT
  • 2,116
  • 1
  • 11
  • 13
  • I completely removed the tools and the reinstalled but that didn't seem to work. I completely uninstalled the new tools (Windows Azure SDK for .NET) and have gone back to using the old (current) Publish features of Visual Studio 2010 SP1. – Joe Jun 13 '12 at 00:39
  • 1
    Why is everything so buggy? Seriously. I had expected more from Microsoft. – Mathias Lykkegaard Lorenzen Mar 21 '14 at 21:00
0

Same issue I have Fixed. Please check if some files are missing into solution. if you are facing error like Error - The target "GatherAllFilesToPublish" does not exist in the project. Then just open .proj file and delete this line <Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" Condition="false" />

You get actual error or those missing files into solution