How to fix The target “GatherAllFilesToPublish” does not exist in the project error
When we upgrade the visual studio and try to publish a project which created from an old visual studio version, we get an error something like “The target “GatherAllFilesToPublish” does not exist in the project”.
The reason seems to be the project files haven’t upgraded correctly. The solution for this error is to update the project files.
First right click on the project and unload the project, Then go to edit mode.
In the top of the project file you can see the section “<Project ToolsVersion=”xx.x”……..”. In here you will see the old version of visual studio. Change this to new version.
Ex : If your project created from VS 2013 then you have version 12.0. If your new version is vs 2017 then change the value to 15.0
Then find the below section in project file
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
Add below code before the above line
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">[your vs version]</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
Then add below line after that line
<Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" />
Finally that section will look like below.
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">[your vs version]</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\[your vs version]\WebApplications\Microsoft.WebApplication.targets" Condition="false" />
Now save the file and reload the project. This should fix the error :The target “GatherAllFilesToPublish” does not exist in the project.
Now you should be able to publish the project.
Thanks a ton! I was merely beating around the bush before I hit this site and it just made my day.
The only thing that I feel worth mentioning that you should have written a placeholder for VS version in this line:
10.0
instead of hard coding it to version 10.0 to make it more readable.
Thanks again!
Thanks Ayan for the feedback. I made the change 🙂