Publish of application fails to find file that exists - asp.net

I've run into this issue when trying to publish my application today that I have published many times before. I'm trying to publish to a directory.
The issue I have is, if I go to my app directory C:\www\clients\clientsite\app\clientproject\Properties\PublishProfiles where the error below says it can't find the file I can clearly see the git.pubxml file.
Copying file Properties\PublishProfiles\git.pubxml to obj\Release\Package\PackageTmp\Properties\PublishProfiles\git.pubxml failed. Could not find file 'Properties\PublishProfiles\git.pubxml'.
I've checked directory security settings and those are proper. I tried deleting my bin and obj but nothing is making a difference.

Often times the solution here is to edit the project file itself in notepad.
The trick to finding the afflicted path is to inspect the OUTPUT window, not the ERROR LIST window.
Once you find the afflicted file path, search for it in the project file and remove the reference.
In most cases the troublesome lines in the project file look like :
<Content include="{your path}" />
Continue to remove the includes until publishing works.
IMPORTANT: if you keep Visual Studio open while you're doing this, you must accept the "reload all" prompt.

I just ran into this after removing all unversioned files from my filesystem (which caused some .pubxml.user files to be lost.
If you right click the project node and click "publish", then select the publish profile that is causing problems, then simply close the publish dialog, Visual Studio will ask if you want to save changes... when you click yes, it regenerate the .pubxml.user file and everything works again.

Have you ensured that the file actually exists in the project? I have had problems working in a team where some file I wrote ended up not appearing in VS as a project file, so when we published, it didn't exist in the publish. If you can't find it inside VS, ensure that you are not debugging, and drop the file into the project file structure, then publish as normal.

VS was saying it couldn't find that file because the git.pubxml file in that directory was of type USER File and it needed to be PUBXML. When I added the correct file type from another version of that same project, I was able to publish the project again. I believe the PUBXML file was removed by mistake in source control.

It usually happens to binary files after updating it. Some packages remove it's own .xml and .pubxml files, while visual studio still believes that it is a part of the project.
What you need to do it to check for a Yellow Triangle besides the file name in the project directory tree, and remove that files, they're useless since your project compiles without errors.

try changing the publishing settings. if you check "Precompile during publishing" this will recreate your .pubxml.user file

I looked in Solution Explorer under the PublishProfiles section and found that the file was excluded and had a "!" by it showing a warning that the file wasn't found. I deleted it, then went into my Publish settings to edit a profile. I changed something (for me to compile files during publish.) Then I tried republishing the solution, and it worked!

Related

Cannot rebuild ASP.NET Web Applicaiton missing solution file

I am taking over an ASP.NET Web Application using C# and all the code (including C# source) was given to me without the solution file (something.sln) so whenever opening the Web Application in Visual Studio 2017 I have to open by "Folder..." instead of by "Project/Solution...". Once open, I am able to make the necessary changes to the code behind files such as Default.aspx.cs or somethingElse.aspx.cs, but when I try to test the code changes by going to Run > Start Without Debugging, I couldn't find the Run menu option; I see the Build Solution button but it's disabled (greyed out).
Every time I try navigating directly to my site at http://dev.mydomain.com. The code changes I made did not get compiled neither.
So how do I get the Run or Build menu option enabled?
The easiest way to correct this issue is probably to create a new, empty ASP.NET WebForms project (and a new solution file as well if necessary) and copy your code files into it. You can then tell Visual Studio to "include" those files in the project.
You may (or may not) need to make the odd other minor adjustment too but those basic steps should get you started.
Not sure if this is related, but adding the sln file to the git ignore removed its visibility from VisualStudio. I had to open the project csproj file in VisualStudio.
THen on close, the prompt was asking me to save a new SLN file with the same solution name i was looking for. I was then able to go to the directory with the original solution in it, and then I was able to open it again in Visual Studio.
For all those who come to this post in the future, I would check your gitignore files and see if they ignored the sln file.

ASP.NET Publishing Web App Copying File Error When the File Has Already Been Deleted

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.
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
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.
Try,
Right Click -> App_Data -> Click Exclude from Project.....
If you get an error like this it's better just to migrate your project to a new solution, that's what I did.

Get rid of Thumbs.db when publish in VS 2010

I changed publish setting, Items to deploy to "All files in this project". Publish not succeed due to error when coping Thumbs.db to temporary path before publish.
Error 49 Copying file help\GenderType_help\images\Thumbs.db to obj\Debug\Package\PackageTmp\help\GenderType_help\images\Thumbs.db failed. Could not find file 'help\GenderType_help\images\Thumbs.db'.
How could I get rid of these unwanted Thumbs.db files to be published.
After I could not find the exact answer this is what I done to contain all the files in copy project.
Changed Items to deploy to Only files needed to run this application.
Change Build action property of all files to Content
Then the all project files with in the copy project without having items to deploy to "All files in this project".
Find the file thumbs.db in your project solution explorer - might need to turn on the show all files setting. Delete the file Thumbs.db from the solution. Then Publish
You can make Windows stop creating them, here are two guides;
https://www.sitepoint.com/switch-off-thumbs-db-in-windows/
http://www.howtogeek.com/210764/fix-file-in-use-deletion-errors-on-network-drives-by-disabling-windows-thumbnail-generation/

ASP.NET publish trying to copy a non-existant file

I'm trying to publish an ASP.NET project in VS2010, and am getting the following error:
Copying file bin\CKFinder.pdb to obj\Release\Package\PackageTmp\bin\CKFinder.pdb failed. Could not find file 'bin\CKFinder.pdb'.
I had tried using a trial version of CKFinder (with CKEditor), but I backed it out. I removed all references to CKFinder, including the folders and the references - or so I thought.
Why is this error coming up? Ideas?
I also bumped to this problem. I was receiving the following error, when trying to publish MVCForum 1.7:
Copying file App_Data\NuGetBackup\Hello.txt to obj\Release\Package\PackageTmp\App_Data\NuGetBackup\Hello.txt failed. Could not find file 'App_Data\NuGetBackup\Hello.txt'.
François Breton's comment helped me achieve the solution.
It's simple:
Open your .csproj file with a text editor (Notepad, Notepad++) Visual Studio will open it as a project.
Press Ctrl + F and search for the file of the problem. In my case the file was "Hello.txt" without commas.
Under the <ItemGroup> it resided:
<ItemGroup>
<Content Include="App_Data\NuGetBackup\Hello.txt" />
<Content Include="Content\admin\Admin.css">
<DependentUpon>Admin.scss</DependentUpon>
</Content>
...More code omitted due to brevity.
I deleted the <Content Include="App_Data\NuGetBackup\Hello.txt" /> line, and voila! Visual Studio allowed me to Preview before publishing!
It will end like this:
<ItemGroup>
<Content Include="Content\admin\Admin.css">
<DependentUpon>Admin.scss</DependentUpon>
</Content>
...More code omitted due to brevity.
Update: I went into Project --> Package/Publish Settings, and clicked "Exclude generated debug symbols." The project began publishing with no issue.
Update #2 (this is probably the better answer): I tried to publish as debug instead of release (yes, I wanted to keep the debug features in this particular release), and the error came up again. It turned out that I did not exclude the CKfinder.dll from the project. Once I did so, it ran with no problem.
Me just removed yellow marked file from my visual studio solution & it worked greatly for me because files were added and removed many times from folders but its not removed from VS solution project.
Delete file showing exclamation mark in the solution explorer. It worked for me
I ran into same problem, i just clicked show all files, and deleted the files that had exclamation mark with them. Hope this helps someone.
Right click on your project => unload project => right click again on your newly unloaded project => edit 'myProject.csproj' => Search for the offending files (CTRL + F) and remove.
If the error appears again within the same parent directory, but now under a different file name, it could be that a user has mistakenly included a file in the project (like I did). All files under the offending directory can be removed. This should solve the problem.
In my case I got a similar error but with .cshtml files like this:
copying to Views\Home\About.cshtml to
obj\Release\Package\PackageTmp\Views\Home\About.cshtml failed. Could
not find file 'Views\Home\About.cshtml'
Looking at the Solution Explorer tree everything seemed fine with no yellow markings but when clicking on a file it gave an error.
The item 'About.cshtml' does not exist in the project directory. It may have been
moved, renamed or deleted.
Removing the files from Solution solved it for me.
You must exclude bin folder from project, then republish your project. the way can solve my problem
I mistakenly included obj Folder to Visual Studio Project. Excluding Obj folder from project fixed my issue
Check for bin folder is added in vs explorer. If it was there then exclude from project and check. It worked for me.
I had files inside of my directory I intended to publish to. Deleting these allowed for a successful publish.
Another solution is to delete publish profile, this error happened to me after I deleted 1 of the EF DbContext. The solution keep track of that file inside publish folder, I recreated the profile and publish successfully.
My error was this
No DbContext named 'xxxx' was found.
These problems occur when the bin file is included in the project, note that if the bin folder exists in your solution, exclude it.

"Add as Link" for JavaScript files returning 404 in debug

Using a Visual Studio 2010 ASP.net web application, I have several projects that share some JavaScript/css files. The most logical way for them to share these files is to place the files in a single folder and each project has them included with the "Add as Link" option. However, if I add the files this way when I'm debugging using either the Visual Studio Development server or debugging using a local IIS web server all requests for these files return 404 Not Found errors. If I publish the site then the files are copied but that obviously doesn't help with debugging.
Is there something I'm missing or is this a failing on VS's part?
To overcome this problem some time ago I created a 'MSBuild.WebApplication.CopyContentLinkedFiles' nuget package. This package adds MsBuild target which copies all content files added as link to project folder during build.
Note: if you use source control then it is better to add copied files (from Web Application folder) to ignore list.
I wouldn't really call that a failing, since you asked for that behavior in the first place: linked items in Visual Studio projects are actual links to external files. Those files can reside anywhere on the disk and are not copied into the project folder.
You might want to copy those files locally yourself during a pre-build event. That way, the files will remain synchronized and you won't duplicate them until your first compile.
The problem seems to be that the website runs right from your source folders, rather than from the bin folder. This means that the file will be missing, whether or not it is copied to the output folder.
It's probable that running from a local or remote web server would not have this problem, though I didn't get that working, and I'd rather not add IIS to my local machine if I don't have to.
Adding a pre-build copy command did work. Note that the current directory will be the bin folder. (You can use cd to echo the current directory to the build window if you want to see it):
If the file is in another solution, your command will look something like (three ..s: one to get out of each of bin, project, and solution folders):
copy ..\..\..\OtherSolution\OtherProject\Scripts\MyJSFile.js ..\Scripts\
If it's in the same solution, but a different project:
copy ..\..\OtherProject\Scripts\MyJSFile.js ..\Scripts
One minor issue is that the link to the file will collide with the new copy of the file, even if you don't add it to your project. As long as you make the link first, it seems to work. If you copied the file first, you'll have to manually delete the copy, and then refresh the solution explorer before before being able to add the link.
Select the link in Solution Explorer and then look at properties window and set Copy To Output Directory to Copy Always. Linked items are set to Do Not Copy by default.
BTW, you can copy many files as links very easily directly from Solution Explorer when using VSCommands 2010 extension.
See this blog post about a simple addition to your project file.
http://mattperdeck.com/post/Copying-linked-content-files-at-each-build-using-MSBuild.aspx

Resources