Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Publish error in Visual Studio

I keep getting this insane error which makes me think VS has gone stupid rather than wiser.

Error 1 Copying file Content\Images\Brands\Lenovo.png to obj\Debug\Package\PackageTmp\Content\Images\Brands\Lenovo.png failed. Could not find file 'Content\Images\Brands\Lenovo.png'. 0 0 PriceCompare

The error is produced when i try to publish to file system. It's stupid that VS is looking for a file which i deleted myself and it doesn't reside in the solution now.

Earlier too i was deleting and adding files but suddenly today the publish command has started giving errors.

In many of the other posts, i have seen people asking to open the .csproj file with notepad and remove the references to the deleted files manually. This seems very daunting as i have deleted a long list of files and added a lot of new ones.

Is there an easier way to get rid of this problem or i need to manually remove the references to deleted file. Can't i just delete the obj folder or empty the bin directory or clean solution or something.

like image 466
Pankaj Upadhyay Avatar asked Dec 22 '11 13:12

Pankaj Upadhyay


People also ask

How do I publish my website in Visual Studio?

On the computer where you have the ASP.NET project open in Visual Studio, right-click the project in Solution Explorer, and choose Publish. If you have previously configured any publishing profiles, the Publish pane appears. Click New or Create new profile. Select the option to import a profile.

What command does Visual Studio use to publish?

Basic command-line publishing 2\publish\. The dotnet publish command calls MSBuild, which invokes the Publish target. Any parameters passed to dotnet publish are passed to MSBuild.


2 Answers

You need to tell Visual Studio that you deleted the files.

Go to the project/solution folder where the files existed and remove them there.

Visual Studio assumes that since you added the file originally, it should be published. It can't assume that you don't want it just because it isn't in the filesystem. Think about using source control in a team - the file may only exist in one persons's machine, but still be needed.

This is not a difficult as you think - the files that can not be found have a semi-transparent look to them, easy enough to select these and bulk delete in Visual Studio. You can also set the project properties to display all files then select all the ones that need to be part of the project and add them in a single operation.

like image 85
Oded Avatar answered Sep 18 '22 22:09

Oded


This basically happens whenever we delete the contents from the folder but forget to remove from Visual studio solutions.

To Resolve this follow below steps:-

  1. Go to visual studio solution explorer and right click on the specific content
  2. exclude from project.
  3. right click and remove from visual studio solution explorer.

Hoping this will help you :)

like image 27
Vikash Pandey Avatar answered Sep 21 '22 22:09

Vikash Pandey