I am using VS2008/VS2010 with Resharper 5, TortoiseSVN 1.6.8.19260-x64, and AnkhSVN 2.1.8420.8. Most operations I do in Visual Studio are reflected fine in SVN, however, renaming folders in a project can cause problems when I try to submit my changes. Also all the namespaces in the C# source files under the renamed folder need to be updated to reflect the name change.
What is the best way to rename the main project folder or any sub folders and ensure there are no issues with SVN? Should it be done outside Visual Studio?
What is the best way to update all the namespace changes? Is search/replace the only way?
Are there any best practices regarding folder names and their contents?
Yes do your rename outside of Visual Studio.
Using TortoiseSVN in windows explorer, do your rename via the TortoiseSVN context menu on the folder in question. The project in Visual Studio will detect the changes on disk and ask you to reload.
You could also do an exclude from project in Visual Studio, then rename and then re-include the new path.
Edit: As per #Sander Rijken below, AnkhSVN tracks the rename and makes sure the rename is correctly registered in the svn working copy.
If you don't have AnkhSVN installed in addition to TortoiseSVN though this will not work and you have to do as I said above.
You should be able to rename folders inside Visual Studio when running AnkhSvn. Also when using refactoring tools like Resharper to change the namespace according to the new folder name, everything works as expected for me.
The Agent SVN plug-in implements the MS-SCCI interface which allows it to integrate with Visual Studio.
Since the MS-SCCI defines a file rename operation, that means Agent SVN can do file renames from within the IDE, as should any plug-in that also implements the MS-SCCI.
What I typically do when having to perform a folder renaming is first renaming the folder using tortoiseSVN, then Excluding/Including the folder in VS and finally renaming all the namespaces (with Resharper it's just a matter of going file by file and Alt+Enter(ing) on the namespace directive to rename as appropriate.
Related
We have a C# solution with multiple projects. We are managing version control for the solution using Github desktop, i.e., outside Visual Studio. After pushing new code to GitHub on a new machine with a fresh install of Visual Studio 2019 community edition, when I add a new file to the API project in the solution, I find that the file gets added to the .csproj file as follows, and the IDE never includes the file in the build, debugging, code completion etc.
<ItemGroup>
<Compile Remove="Controllers\TestController.cs" />
</ItemGroup>
I also see a + sign next to the TestController file in Solution Explorer. Hovering over the + sign brings up the message "pending add."
Why is this happening? And is it safe to just remove this itemgroup block in the .csproj file? Is there a way to prevent this behavior for new files added to the project?
Details
Context:
C# solution with 5 projects - (1) WebAPI, (2) Identity, (3) DataAccess, (4) Services, (5) Shared libraries. Editing using Visual Studio 2019 Community Edition.
Full timeline:
Solution pulled from GitHub.com using GitHub desktop
Files added to DataAccess and Services project using Visual Studio. Everything was fine
New branch created in GitHub desktop. New files added to the branch using GitHub desktop and pushed to GitHub.com using GitHub desktop
Code merged with parent branch by project administrator
Local solution synced to remote repository using GitHub desktop
--- alert: problem seen now ---
New file (TestController) added to the API project using Visual Studio. This file does not become part of the build. IDE does not highlight ApiControllers, ControllerBase etc, does not indicate errors for mis-spelt services, pressing F11 on ApiControllers gives error message "cannot navigate to the symbol under the caret."
Google search suggests checking on .csproj file. Here I find that the new file is within the 'compile remove' block.
Is it safe to edit .csproj file in Visual Studio 2019?
If you know what you're doing and you do it correctly, sure. Otherwise, not so much.
Why is this happening? And is it safe to just remove this itemgroup block in the .csproj file? Is there a way to prevent this behavior for new files added to the project?
It's happening because a file showed up in the project subdirectory that Visual Studio doesn't have as part of that project. So it adds the <Compile Remove... /> element to exclude it from being compiled as part of the project. It is safe to remove the element, but in my experience it just shows up again.
As a general rule, you should not be adding files to project directories managed by Visual Studio, except by using the Visual Studio UI itself. It's not clear from your post why you are doing this. The directory you apparently are adding files to is your project directory. It should only have files that do in fact belong to the project.
The best fix is to not try to add files to a project directory when they shouldn't be part of that project.
You may have an XY Problem. If you can post a new question in which you explain the scenario in which you've added the files that don't belong, and ask for guidance to accomplish whatever broader goal it is you have, but without running afoul of Visual Studio's rules, you may get a better answer than "don't do that".
I think I have identified the problem. I believe what happened is that once the local branch was pushed to remote, further changes to the project made using Visual Studio were not being integrated into the project, even though I was not formally tracking the project in Visual Studio.
git status showed that I was still on my initial local branch. I did the following to sync with the remote parent branch and then start a new local branch:
git stash
git checkout <parent_branch>
git pull
git checkout -b <new_branch>
This switched me to a new branch, and now I am able to edit the file as usual.
I'm using Visual Studio 2017 ver 15.5.0 Preview 2.0, but I've seen this in other versions. When I rename a code file in the solution explorer, sometimes it asks me if I want to rename the associated code element as well:
Other times it does not. Under what circumstances does it not do that so I can try to avoid them?
EDIT:
I found one easy way to repro my undesired behavior. Create a project. Create two folders in the project. Create a class file in one folder. Drag the class file into the second folder. Rename the class file; note you are NOT prompted.
My Visual Studio is not showing a lot of the available classes in the IntelliSense auto-complete. For example, a project I'm working on has a reference to the Microsoft.Xna.Framework namespace, yet even after adding the using statement using Microsoft.Xna.Framework in a file, IntelliSense is unable to recognize classes like Texture2D and Rectangle. I can still type them in, however, without getting a compiler error. Any idea what's happening?
The IntelliSense detects standard libraries like System.Diagnostics but not any external ones.
It is not a NameSpace conflict issue because classes within the current namespace are also missing from the IntelliSense.
I have tried:
Restarting Visual Studio (With and without closing tabs)
Deleting the contents of %LocalAppData%\Microsoft\VisualStudio\14.0\ComponentCacheModel folder
Resetting import and export settings
What worked for me is unloading and reloading the project
If unloading/reloading the project doesn't work, try deleting the .suo file found in the SolutionName/.vs/ folder. The .vs folder is an auto-created, hidden folder so you will have to show hidden folders in order to see it.
I am using ReSharper. What worked for me:
Unload project.
ReSharper > Options > Environment > General > Clear caches
Close solution.
Exit Visual Studio.
Restart Visual Studio.
Reload project.
Do you have ReSharper or any other plugins installed? There sounds like a similar issue/solution here. It may be third-party plugins at play depending on what add-ons you have.
Try saving and reloading the files.
I don't know why it happens, but it happens to my work laptop occasionally, typically reopening the source file resolves it.
OK so probably not the best solution but it works. I reinstalled Visual Studio and the problem was fixed. Also, it hasn't shown up since (this happened about 3 months ago).
another dumb solution))) Determine which classes/namespaces are not showing up. Then go to that project where they are. In that project pick any .cs file copy its contents, then delete that file and create again))
Click on the class not showing and Change Build Action -> to Compile
it happens sometimes when you add class as content or other resources
I read few things regarding this issue but I'm still a bit confused so I will try to present my scenario and questions.
First of all I read that you shouldn't store your .sln file in the same folder as .csproj. The reason for this is that when you will try to add a new project it will be added above the directory with .sln file.
This is from Visual studio 2010 best practices: [Link]
Now I'm using VS 2013 so is this any different ? Because when I create a new project its root folder is placed exactly where the .sln file is.This is for all the projects created using New project... in Visual studio and later using Add new project.. clicking on solution in Visual Studio.
The reason I ask this is because I copied a project using this step by step [Link]
and everything is working great except the part with the .sln placing. To copy the project I delete the .sln of the first project and let visual studio create a new one. By default Visual studio tries to do that in the same directory as .csproj. So I go one directory above and place the .sln there. The problem is with adding a new project. It actually starts to behave as in the example from Visual Studio best practices book (creates new project one directory above).
I hope all of this is not too confusing. If so I can elaborate.
This is a very important topic since I will be doing this fairly often(copying projects) and I need this to work exactly as it should.
Cheers!
When you create a new project (File-->New-->Project) there is a check box Create directory for solution. Ensure that is checked to create a folder for your solution and a sub-folder for your project.
If you create a new project from scratch, you'll see how Visual Studio creates a project / solution by default:
Solution Folder
Solution.sln
Project1 Folder
Project1.csproj
Project2 Folder
Project2.csproj
etc
I want to be able to rename classes with associated file in VS without loosing file history in Perforce.
I thought I could include an Perforce command (p4 move...) in file renaming of Visual Studio
or in class-renaming of ReSharper.
I see 3 options:
Wrap Visual Studio's file-renaming
I extend the file renaming (I mean with file renaming: right-clicking file in Solution Explorer and selecting Rename.) by an own VS add-in or a macro that wraps the existing Rename menu command and calls p4 move....
Extend Visual Studio's file-renaming
I extend the file renaming by any kind of hooking into existing Rename command.
Extend ReSharper's class-renaming
I extend ReSharper's class-rename action (Ctrl+R,R) (with enabled option: Synchronize file names accordingly to changes) by calling p4 move....
Which option is the best one to rename a class with associated file in VS without loosing file history in Perforce?
I have no experience with VS add-ins and ReSharper plug-ins. So if anybody knows that an option is not possible at all than a hint would help me very much.
Any idea?
You can extend file renaming in VS 2010 by using a macro for adding a "p4 move -k" action to the rename event.
See answer of "How to keep change history while renaming files in Visual Studio using Perforce".
This macro calls automatically a p4 rename/move when you do any rename or move action in Visual Studio. So you keep the file history in Perforce.
Git handles these types of changes pretty well. Could you move to using Git for your development and using Git-P4 to get the source into Perforce? I don't know Perforce so I'm unsure how well this solution works, but it is definitely something to look into.
Do you have the new P4VS plugin? I believe it supports renaming pretty well.