Move Project To a New Folder in Visual Studio - visual-studio-2019

Here is my Solution files structure (folders are prefixed by +):
+FooProject
FooProject.sln
+Tests
+BarTests
BarTests.csproj
Now I want to move the BarTests project to a new subfolder UnitTests:
+FooProject
FooProject.sln
+Tests
+UnitTests
+BarTests
BarTests.csproj
I tried the following ways but to no avail:
If I add a New Solution Folder, UnitTests, in Visual Studio, and move the BarTests to UnitTests folder in Visual Studio, then no new folder is created on disk, and no changes to the solution file are made, hence can't propagate this change in the source control.
I create the UnitTests folder directly on disk (using File Explorer or Command Line), move the BarTests to UnitTests, and then manually update the solution file to reflect this change in the path. Now the problem is in Visual Studio, I still see the BarTests project under the 'Tests' folder and not the UnitTests folder.
I tried the second approach even after closing VS and deleting the .vs folder but still the same behavior.
What am I missing here?

Solution folders within Visual Studio are just used to organise solution-level assets such as projects and other solution folders within Visual Studio itself and are not permeated to disk.
When you move a folder on disk and change the reference to it within the .sln file, you are doing exactly that.
Really simple solution, do exactly what you have tried already and you can even do it within Visual Studio by switching to "Folder View" within the Solution Explorer.
Unload or remove the BarTests project from the solution within Visual Studio.
Create your physical "UnitTests" target folder on disk in the desired location and move the BarTests project folder and files to the target location.
Return to Visual Studio and repeat, create your solution folder for UnitTests and then add your project to that solution folder (if you removed then you select "Add existing project" from the menu).

Related

Confused about adding an existing file to Team Foundation Server (TFS)

I am trying to add the file "DSTB_QB.xml" to an existing project in TFS. I added the file to an existing project from Source Control Explorer using "Add Items to Folder", but I have to check it out separately from the rest of the project. Additionally, although it appears in the "App_Data" folder (which is where I want it) in my local workspace, it does not appear under the "App_Data" folder in Solution Explorer. It is as if this file is under source control, but not part of the project. How can I make the file part of the project?
You can not add just with Source Control Explorer because you Visual Studio Project does not know why some file exist on file system (maybe this temporary file). But if you add existing file with Solution Explorer to existing project this file will be added to source control automatically.
I fixed the problem by right-clicking on the "App_Data" folder in Solution Explorer and selecting "Add->Existing Item". I'm not sure if that's what the above commenter meant, but it worked.
Now my question is: Why did I have to add the file in Source Control Explorer AND in Solution Explorer? More specifically, why wasn't adding it in Source Control Explorer sufficient?

relocated MVC solution folder in ASP.NET

When I create a MVC project in Visual Studio, it will automatically generate a solution folder with the same name alone with .sln file, packages folder.
For example:
/MyProject/MyProject
and when I run the application in server:
http://XXXXX/MyProject/MyProject
I hate the address. I want to the address looks like:
http://XXXXX/MyProject
I tried to move the solution folder to upper level directory, however, the MVC project can still run but show errors and many warnings.
Is there any way I can create a MVC and I can specify the solution folder? or I can relocate the MVC solution folder nicely?
Thanks
You can relocate sln file.
Just close solution, move sln file to project folder, and then open sln file in VS.
Project will not load. Delete unloaded project in Solution Explorer, then right click on solution (in Solution Explorer) Add => existing project...
and select .csproj file of the project.
Rebuild application, nuget will restore packeges.
But I don't know why You hate path.
You can name solution folder with diffrent name then Your project. when You add more projects every project folder will be in one solution folder and path will looks like:
http://XXXXX/Solution/Project1
http://XXXXX/Solution/Project2
And one last thing: You probobly don't want whole solution in application server, you can just deploy project as web deploy packege.

How to rename C++ source files in Visual Studio 2003?

I have several C++ projects in a few separate solutions in Visual Studio 2003.
I need to rename several of the directories and source-code files in these projects.
How do I rename directories and source files such that VS will recognise the new names?
If I change file names in the OS, VS ignores them. It still shows the old file names in the Solution Explorer, and double-clicking those produces an error message (something like "Could not complete the operation").
The Solution Explorer doesn't seem to provide any way to rename files.
I can select a file and see properties such as what file-system path it points to, but I can't change any of those properties.
I'm not using integrated source control.
I solved the problem in a few ways.
If I rename a directory containing a project used in a solution, I can either edit the SLN file directly, or open the solution in Visual Studio, then remove and re-add affected projects.
If I rename a source file used by a project, I can edit the VCPROJ file, as this contains the paths of all source files in that project.
I also had to check all projects for "Additional Include Directories" and "Additional Library Directories". Some of these referenced renamed directories.
I eventually fixed most of these using a separate text editor's "Find in Files" function to find directory references. This was faster than using the VS UI to check properties of each project.

Adding Sub Folders to Content Folder

I want to add folders/sub-folders/files to the content folder of MVC3 project. I added some folders with sub folders and files to the Project Directory of Contents Folder in Explorer. However, when I try to add them in visual studio, it will not let me add the folder and its sub contents, but keeps navigating to the files in those folders. Why can't I just add the folder, and its sub folders with files. It only allows adding the individual files to the Contents root folder and does not create the folder structures. I want to maintain the folder structures in the Visual Studio Project, but can not.
in VS2012 and others, make sure that you have the option "Show All Files" selected in your Solution Explorer. This will show all the content, subfolders and files in your project.
If your using any source control, ensure that you 'right click' on the folders or files you want to add and choose "include in project" from the pop-up menu.
The reverse of this also works to "exclude from project".
I ran into this issue myself, when first getting into VS, and got quite frustrated at adding content through Windows Explorer, but not being able to see that content appear in the Solution Explorer.

Why do empty folders disappear when adding Visual Studio solution to TFS?

I have this Visual Studio solution that includes a project that has a template folder tree consisting of several empty folders. When I add this solution to Team Foundation Server (TFS) using the "Source Control -> Add Solution to Source Control" menu item it doesn't add the empty folders to the TFS repository! I really need those folder to be present when the code is downloaded from TFS.
Now, I know I can create the folder structure using Source Control Explorer, but since the whole project is managed from within Visual Studio it feels kinda wrong to create these folders in a separate way.
Is there some setting I need to adjust so Visual Studio will also create TFS folders for empty project folders?
Apparently it's a feature, not a bug:
"in the Add files to source control we
do not support the addition of empty
folders, but in our research our users
preferred the SCE toolbar button for
actually creating their empty tree
structure rather than going to the
file system, doing it there and then
adding to source control."
http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=119974
In TFS2008 you can drag and drop folders from Windows Explorer into source control explorer, and empty subfolders will be created when checking in. Not sure if this works in TFS2005, I don't have an instance handy to test it - anyone?
Drag and Drop folders worked for me on TFS 2008, although it didn't on TFS 2005.

Resources