A file or folder with the name already exists Visual Studio - visual-studio

I try to add a new file to my source controlled solution and receive this message:
A file or folder with the name 'xxx' already exists. Please give a unique
name to the item you are adding, or delete the existing item first.
I'm 100% sure that there is no file with the given name.
So how do I get VS to add items again?

Restarting Visual Studio didn't help, the folder is cached on the system.
Open Solution Explorer there is an icon that looks like a many Pages: which is the Show All Files. Once clicked, one is able to see the hidden, to the visual studio project, the folder that was causing this error. (Look for the folder in the View section.)
After I deleted the unwanted folder, and Rebuild Project, You should be able to Create the controller which will create the view automatically...

Restarting Visual Studio helped me.

Steps if a folder is Missing
In the Solution Explorer window
Select visual studio project which holds the missing folder.
Select or turn on the Show All Files button ( ) to show the existing, but missing folder.
Select the hidden folder then right click and select the menu item Include in Project to add into the project in the project view.

Simply, On Solution Explorer Right CLick on Project's name -> Unload Project.
then right click on the same project and click 'Reload'.
Problem is Fixed (y)

If you're using MVC, and trying to create a new Controller, you should also check the Views and Models. Even though there was no folder or file with the Controller name, I had to delete a View folder with the same name (that already existed for some reason) using Show All Files and rebuild the solution.

I right clicked and removed folder. Then Clicked upper the folder I wanted to create project in and created project. In the Location section I opened the File explorer and the file I had deleted still appeared -> deleted it from here and then went ahead.

I fixed it by actually adding a file and then deleting it again.

The project file was unloaded in visual studio 2017
The easiest way is to copy your project folder and paste different repository then open your project in visual studio then after run the project, it should work.
for example
(D:--------->E:[here i mentioned repository these things])

Visual Studio 2017 v 15.9.12 ... I ran into this problem, but with no actual folder conflict. In my case, I had solution folder named NewOrder, and I was trying to create a child project with the same name, but encountered the above error. I tried closing and reopening the solution (didn't restart VS so not sure if that would have made a difference) but here's what worked for me.
renamed solution folder
created my project. At this point, I got a strange error about not being able to locate the .net standard 2.0... so then I did restart VS, which fixed that problem
renamed the folder back
Now everything works fine. I restarted VS again just for good measure and all works fine now.

In my case, when trying to add a new project to a solution, even though a project with the same name had been removed from the solution in visual studio (2019), I had to open file explorer and delete the folder for the removed project.

I just had a tab open with the file name, closing it solved the issue for me

Click on Show All Files Menu in Solution Explorer and See That file in Controller, Views and Model Folder and delete that from there also

You need to give attention if adding a file automatically add other files/folders..for example if I added a controller which automatically add folder with controller name in views..I couldn't add controller .cs file until I deleted folder with controller name from views.

Related

Rename project folder in Visual studio and Team foundation server

My Visual Studio 2013 solution has a project "Test". I can rename it in solution explorer, but I also want to rename the project folder in disk and also reflect the change in Source Control(TFS). How can I easily do this?
Thank you
#CodeCaster, Thank you. Based on your advice, I have done some quick experiment, and worked it out. First step is rename the folder name in TFS; the new folder will appear in local workspace and all contents of the folder moved to this new folder. The old folder stays there with rest content which not belong to source control. You can delete it manually.
Or
Using TFS Power Tools to rename from Explorer.
I followed those steps to preserve the version history of the files inside of TFS:
Rename/move project file (.csproj) in source control explorer in VS (alternatively, this also works from within VS Solution explorer, simply select "rename")
Rename/move project folder in source control explorer in VS
now the project should be unavailable in VS, solution also gets closed
remove project from VS
add project (new path) to VS
fix project references in other projects
adjust namespaces if desired
adjust assembly name and default namespace in project settings
Don't know of an easier way. Was searching for this myself, and this should be the way to go.
I think you can rename it from the TFS Database.
Try going into tbl_Project of the Tfs_DefaultCollection Database, which you can find on the SQL Server Instance used by tfs. You can know which one is that by going into the TFS Console, click on Application Tier, then find the details of the Server under the Data Tier Summary. Run an update query against the project you want to rename.. I haven't tested this but just assuming it should work (some educated guess)..
I am using TFS 2015 Express and rename project is grayed out.
You can still rename the project using the TFS Site for the project.
Here is a link that shows how to do it.
https://www.visualstudio.com/en-us/docs/setup-admin/rename-team-project
I was facing a similar issue while trying to rename a folder in Visual Studio 2015.This is what I tried.
Right click on the project file
Open with Notepad
This will generate your current solution file
Change the occurences of your prev file name. (Find and Replace with the desired name)
Save it and close
Change solution explorer name and rename the folder to your desired name.
This should work.

How To ReInclude Excluded Folder

So I just performed the coup de gras on my project by accidentally clicking on Exclude From Project instead of Add on my controllers folder.
When trying to add a folder named Controllers I get the error "this folder exists". However, If I try to click on the project -> Add Existing... I cannot select a folder, but only the controllers.
Kind of at a loss here, has anyone had experience with this, or does anyone know how to get the folders back into the solution?
Click on the Show All Files icon in the solution explorer and then simply include the folder:
Visual Studio Express 2012
Select Your Project Folder Click On "Show All Files" icon to show all Excluded Folders And Files
Then Right Click on Excluded Folder or File and Click on "Include In Project"
In my ASP.Net Webforms project after excluding the file I could't find it even under 'Show all files', but they were at project folder so I had to right click on project in Visula Studio then add existing item.
For anyone wanting a different solution, you can also browse to your project in a File Explorer and delete the offending folder (Be sure to copy it somewhere safe first!). Restart Visual Studio and proceed to add the folder as you regularly would.

Visual Studio C++ - Resource View blank?

I have a Visual Studio 2010 C++ project which was copied from another visual studio project and renamed. The project compiles fine and works. However recently, I went to the Resource View to edit some dialogs and the window is completely empty. I can't remember if I went there since I copied the project or not:
Any ideas on how I can get this back? I'm thinking there is some cache somewhere?
UPDATE
I should add that this solution is a multi-project solution and normally in the resource view even if a given project does not have resource files you will still see a "folder" for the project in the resource view tree view. There are no "folders" for any of the projects in the solution.
I should also add that other solutions that I open in visual studio will display the resource view fine.
It might be because your Browsing/Navigation Database is disabled.
Check the current setting under:
Tools -> Options -> Text Editor -> C++ -> Advanced. "Disable Database" should be false.
This is a bug as far as I know, and they said they are working on the problem.
More Info:
http://connect.microsoft.com/VisualStudio/feedback/details/535971/solution-resource-view-empty-when-option-disable-database-c-is-set-to-true
I had similar problem that I solved with reloading projects in the solution (unload projects and then reload all projects).
I had the same issue today, and my class browser was also empty. I fixed it by deleting the ipch directory and the sdf file from the solution's directory. Visual Studio reinitialized the intellisense databases, and the view were back.
Try to find the .rc file in your Solution Explorer, then double-click it which should reload it in the Resource View.
Also check to make sure the .vcxproj file is referencing the correct .rc file (open it up in a text editor). Perhaps you renamed it or something.
Woohoo! Figured it out. Since each project normally has a entry on the Resource View tab regardless of whether it has resources or not, I decided to add a new temp project to my solution to see how visual studio would handle that. So I right clicked on my solution and clicked Add->New project.. and added a new Win32 project with the setting of static library and MFC checked. Once I added the project and went to the resource view all my other projects were back! Then I just deleted the temp project I created.
I'm not sure what it did, but it must have forced visual studio to rebuild some internal cache or something.
I've had the same problem: Resource View was totally blank for a solution with several projects.
I had moved the entire file heirarchy's top directory to a different place (different disk mount too) which probably had something to do with it.
After I finally got all the paths changed (files in projects, the the projects' include and lib paths and so on) and started back on developing, I noted the Resource View was empty, and clicking on the .rc file didn't make anything visible.
But, saving the solution and restarting did the trick.
Simply closing & re-opening the Solution worked for me (VS 2017).
This can also be caused when forcing VS2010 to write browsing information to a location which doesn't exist. For example when settings are exported on another machine and then imported on a new machine which doesn't have this path.
In the following sample, I was forcing browsing information to be written to my local temp folder. When I imported my settings from an old computer, the path was pointing to a non-existent path.

how to rename a project without killing solution

When I rename a project within a solution, and then try and build that project, I get the error: "The project file "xyz.csproj" was not found. Where xyz is the old project file name!
The annoying thing is that I can search my project & solution for the old project file name, and the search will come up with nothing, and when I click on the error VS does nothing.
So there seems to be no way of finding where the old reference is.
This is a .web project hosting a silverlight page, if that makes any difference.
These are steps I follow when I rename a project:
Click on the project in the solution and rename it. This renames the .proj file and the project name(but not the directory containing the project).
Close solution, rename the project folder. At this stage, the solution still references the old folder.
Open sln file and replace the old folder name with the new one. This should only be in one place. it will look something like this.
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SolutionName", "OldProjectName\NewProjectName.csproj", "{98644DD0-5AB5-4CAC-8D83-CCB8EEEFE234}"
You will need to make it look like this:
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SolutionName", "NewProjectName\NewProjectName.csproj", "{98644DD0-5AB5-4CAC-8D83-CCB8EEEFE234}"
With all visual studio projects, you can usually just close visual studio, edit the solution/project files with a text editor, and reopen visual studio. They're just XML. As long as you're careful not to change anything major, a search & replace in a text editor should do the trick.
OK this was my problem.
I deleted the service reference to the project I renamed, but still got the error message, then via some trial and error adding and removing projects I found that there is a "WCF Ria Services Link" Project property, doh.
That's a bit of a trap.
I also had to rename the namespace and point the project's startup object to the renamed program:
<old_project>.Program to <new_project>.Program

Visual Studio: Create a web application from existing code

I have an existing directory structure that is all nicely checked into SVN, so I don't really want to mess with it.
The website code lives in a folder called C:\Projects\TheProject\Website. I want to bring the website files into a new Web Application Project without changing the directory structure.
Ideally the resulting file structure would look like this:
C:\Projects\TheProject\TheProject.sln
C:\Projects\TheProjects\Website\Website.csproj
No matter what I try I dont get what I want. There is no option to create a web application from existing code. This is very frustrating. Does anyone know if it is possible?
OK I figured it out. It's weird, but the following steps will work:
Open fresh copy of Visual Studio
File->New Project, select Web Application
Use the following settings:
Name: Website (this is the name of the existing folder with the website files in it)
Location: C:\Temp\ (anywhere will do for now)
Solution Name: TheProject (name of the existing project's root folder)
Check "Create directory for solution"
Delete the auto-created Default, Global and Web.config files
Save All and close Visual Studio
In Windows Explorer, copy the new folder on top of the existing folder so that the files are merged.
Double click on the sln file to open Visual Studio again.
Select "Show all files" (at the top of Solution Explorer)
Right click on any files or folders you want to add and select Include in Project.
Have you tried something like this?
Create a new Visual Studio Blank Solution from File-->New Project-->Other Project Types-->Blank Solution, making sure to specify c:\Projects\TheProject as your solution directory.
Copy the folder with all of the existing website stuff into c:\Projects\TheProject\WebSite.
Back in Visual Studio, right-click your solution in Solution Explorer and select "Add Existing Website." Then, pick your c:\Projects\TheProject\WebSite folder.
Good luck, HTH.
Create a new web project with a .csproj file. Delete all the files it comes with. Drag everything into the project.
In the File menu, click Open, and then click Web Site. Choose the root folder where your Web Site is located
On top of #cbp answer I would like to add that if you would like to keep the Version control history of those files - in step 6 - instead of copy do:
git mv original-website/* new-web-application-directory/.
What have you tried? I normally create a blank solution and add existing folders (drag and drop on solution explorer works best), and have not had a problem.
in VS 2008 File->New->Project From Existing Code

Resources