Publish error in Visual Studio

publishvisual studio 2010

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.

Best Answer

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.