2
votes

I'm having a very peculiar issue in Visual Studio when trying to publish my MVC Web App on IIS, Windows 10. It is trying to copy a file that no longer exists in my solution. This is the error:

Severity Code Description Project File Line Suppression State Error Copying file obj\Release\AspnetCompileMerge\Source\Views\Demo\File.cshtml to obj\Release\Package\PackageTmp\obj\Release\AspnetCompileMerge\Source\Views\Demo\File.cshtml failed. Could not find file 'obj\Release\AspnetCompileMerge\Source\Views\Demo\File.cshtml'. Solution 0

This file does not exist anywhere in my solution so I am unsure as to why it's trying to copy this file. I've tried restarted Visual Studio, cleaning and rebuilding my solution, deleting the .vs folder, but all of this has been for naught.

4
Erlier Did you delete file.cshtm ? - Udara Kasun
@UdaraKasun I did yes, everywhere it could possibly be located for this solution. I had to migrate my solution to a new one to fix it. - user9972789

4 Answers

3
votes

Solution 1

After you deleted file from folder (Not in the visual studio) usually become this error message. the reason for your "projectname.CSPROJ" file already recorded your deleted file reference

Eg : <Content Include="Views\home\Index.cshtml" />

Then you can to delete that reference from in your "projectname.CSPROJ"

Solution 2

if you can see file in the project, You can right click on the file and Exclude file from the project

after that you can publish your project without error

0
votes

Try, Right Click -> App_Data -> Click Exclude from Project.....

0
votes

If you get an error like this it's better just to migrate your project to a new solution, that's what I did.

0
votes

I am using VS 2019 and was getting the same error. For me the reason seems to be the solution location. The file path was exceeding 200 chars. After I copied the solution in c: drive it started working for me.