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
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 have upgraded from 2018.3.14f to 2019.2.13 and I started having really strange errors.
I am now having those two errors:
The type or namespace name EventSystems' does not exist in the namespaceUnityEngine'. Are you missing an assembly reference?
and
The type or namespace name UI' does not exist in the namespaceUnityEngine'. Are you missing an assembly reference?
This is happening only to the project which I upgraded from 2018.3.14 to 2019.2.13.
If I create a new blank project with 2019 there is no issue. The namespaces are found plus when I go to New2019Project/Library/ScriptAssemblies/ I can see the following files:
Then If I go to my upgraded old project in this dir OldUpgradedTo2019Project/Library/ScriptAssemblies/ the folder is having only those files:
As you can see I don't have those files in my updated project. If I try to copy the ones from the new working one into my old upgraded, at the time I start the Unity for the upgraded old project it deletes them and the problem stays.
Is there any way I can fix this annoying problem?
What fixed this issue for me was to update to the latest 'Visual Studio Code Editor' in the Unity Package Manager. To do this, go to window -> package manager -> set 'All Packages' to 'In Project', select the Visual Studio Code Editor and update.
I was experiencing the same issue, but my problem was that I had multiple Google.VersionHandler.dll files in separate folders within Assets. As a result, the .asmdef files were not loading. Here's how I fixed it:
Close Unity and Visual Studio
Remove the extra copy of Google.VersionHandler.dll
Delete all .csproj and .sln files
Delete Library, obj, and Temp directories
Reopen Unity
Click Assets > Open C# Project to regenerate .csproj and .sln files
Hope this works for you!
I update my Visual Studio 2017 to Visual Studio 2019, then everything works.
Hope this works for you.
I am trying to create a new visual studio solution (.sln) and want it to place in an existing directory structure.
For example:
Existing Directory Structure:
ParentDirectory
Sub.Directory1
Sub.Directory2
I wanted to create a VisualStudio solution with name Sub.Directory1 and place it parallel to Sub.Directory1 folder i.e. as a child of ParentDirectory.
Creating a new solution with the requried name was not possible since VisualStudio always create a directory for new solutions (https://social.msdn.microsoft.com/Forums/vstudio/en-US/c1579334-2b06-4c51-a8d1-7e3443b7e843/uncheck-create-directory-for-solution-for-new-blank-solution?forum=vssetup).
So I created new solution inside Sub.Directory1 folder and now trying to move it to parent directory by using SaveAs menu option in visual studio and pointing it to ParentDirectory.
But everytime I click Save button, VisualStudio goes into Sub.Directory1 folder.
(Note: I am using Visual studio 2015 (version 14.xx.xx) latest)
Can anyone help me out here?
I am trying to develop a template Visual Studio 2008 solution making use of the IWizard interface. So far I have been able to successfully add multiple projects to the solution. I am now looking to put in a Web Setup project into the solution which will already have the Project Output from a particular project specified.
I read that a .vdproj file cannot be part of a template, so looking at any other alternate options available.
One option that I tried but did not work was to save the contents of the .vdproj file within the wizard and write it out after the solution gets generated. I am wondering if I can use the Visual Studio ExecuteCommand to add a Project and add the Output Group in the setup project without displaying the UI.
Anyone tried this before?
I found the answer.
The method of saving the contents of the .vdproj file within the wizard works. However, before writing out the content to a file and adding it as a project, the GUID of the project which would be used in the Setup project (Project Output or Content Files) has to be replaced in the saved text.
Visual Studio adds a unique project GUID once the project gets added to the solution, and this GUID has to be read using the Visual Studio SDK and replaced in the actual .vdproj file text.
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.