I have Visual Studio 2017 project in which I need to open a folder named Devdog.General, which is also included in my Solution. However, it won't recognize it as an existing folder and gives me a missing directory / namespace error when I try to import it. See screenshot for more info.
Try this button:
I had a similar problem the other day and it had to do with files that Visual Studio didn't know were part of the project because they'd been created externally (and that included folders). Visual Studio could see them but it was hiding them from me.
After clicking that button, you will be able to right click on the folder and select "include in project" which will include the files for compilation and navigation.
First, try selecting any of your "*.cs" files inside this "General" folder and check in the "Properties" view if the Build Action is configured to Compile. Visual Studio will only compile your file if it has the correct build action.
Secondly, open that "*.cs" file and verify if the namespace defined inside it is correct. For C#, folder structures don't matter much: what really matters is the namespace you have defined your classes in. You can define your classes in namespaces completely different than the folder they are included in your project. That is completely arbitrary, and up to your organizational needs.
An image illustrating what you need to check (and where) follows.
Things to Check
1.) Check the namespaces inside .CS files - they collectively create usable namespaces you are referencing - not folder names. If you create a few files, then move them to a folder, and create newer files inside that folder they will have different namespaces. The newer files will have the default Namespace value followed by .FolderName. So be sure to check that out.
2.) CSPROJs can get hosed and lose reference to folders that display in the UI. Remove the folder from the project (through the VS2017 UI, right click and choose that option). DO NOT DELETE. Then recreate the folder in the UI (it shouldn't let you, navigate to the folder directory manually and rename the folder.OLD temporarily). Once the folder is rename, try recreating the folder. Upon success move all your CS files into the new folder from folder.OLD. After files and folders are back to where they were essentially, then in Visual Studio, "Add existing items" on your .cs files. This recreates the CSPROJ references one by one.
3.) Unload CSPROJ, right click and Edit CSPROJ to manually check all the .CS references in ItemGroups. Make sure its myfolder\myotherfolder\mycsfile.cs.
4.) Remove reference to other projects that contain namespace, and re-add them. Verifying, one by one, the namespaces begin reappearing in Intellisense as recognized.
5.) If you try the above step, close Solution, close Visual Studio, navigate to SLN folder container, and delete hidden folder .vs and then reopen everything.
What happens is sometime a folder rename or file transfer doesn't propagate to the .CSPROJ folder, a namespace then doesn't get intellisense cached, and errors galore show up.
Please check your folder name and namespace name. probably folder name and namespace did not match
enter image description here
Related
So I've downloaded a framework to write code within, and I needed to link the source code to an executable file to allow the code to run. However, moved the root folder (containing all files related to the project) from the folder it was in previously, and now nothing works. I've been attempting to change the paths for the files to be relative to the root folder within the properties tab, but I'm not sure how to go about it.
Path to Executible - C:\Users\me\Downloads\Competition-Pack-v43-GeometryFriends-updated-14-08-2016\GeometryFriendsAgents\GeometryFriendsGame\Release\GeometryFriends.exe
C:\Users\me\Downloads\Competition-Pack-v43-GeometryFriends-updated-14-08-2016\GeometryFriendsAgents\GeometryFriendsGame\Release
Is there an equivalent to using Macros to define paths in C#, like you get when you build a C++ project?
Add the .exe as a resource (non embedded) to your project, and set the "Copy to output" property to copy always. This ensures the needed exe will always be relative to your build path. The simply use relative paths in your code.
Example:
(This is all done in VS's solution explorer window)
Right click your project, and add a new folder, name it Externals.
Right click the folder, click Add, and then Existing item. Locate your exe, and add it.
Now right click the exe, select properties, and set the "Copy to output" property to anything other than "Do not copy".
Now, anywhere in your code, use the path "Externals\YourExe.exe". The double backslash is to unescape the backslash. An alternative would be to use #"Externals\YourExe.exe", which turns the string to a path during compile time.
There you go, when you build, the exe will be automatically copied to the build directory's "Externals" directory, and always be relative.
It turned out in the end that Visual Studio has a Macros option for this very task.
When you're looking at your include directories window as in the image above, there's a button labelled Macros. Click that, and it gives you access to a list of predefined paths. They all start with a $, like the ones already provided that point to the include folders for Visual Studio.
In my example above, I added $(MSBuildProjectDirectory), which points to the exact folder that I needed on the drive my code folder was located on. Hope I can help at least one or two people with this, cause it drove me insane until I came across it.
Not sure how to describe my question and ok here it goes:
We already have some existing projects created and under TFS source control.
A typical project is then stored locally as:
SomeDir\SomeNameSpace.SomeName\ProjectName\
then the csproj and sln file inside that directory will be named: SomeNameSpace.SomeName.ProjectName
Now when I want to create that same setup using Visual Studio it goes horribly wrong:
I have tried all possible options on creating a project and either it creates an extra SomeNameSpace.SomeName.ProjectName folder extra under the ProjectName directory and puts the sln and csproj inside that dir or I can create a Project under the proper ProjectName dir only then the name of the sln and csproj files will be ProjectName.snl/csproj which is neither what I want.
Renaming them of course would be the logical thing to do, however, doing that causes the sln to go corrupt. When I try to reopen it will throw a Save as DevEnv.sln in my face and that is not what I want.
Edit: Of course I have renamed inside the sln and csproj file which neither led me to the solution
So how can I create a new VS2015 solution that will nicely sit under
\SomeDir\SomeNamespace.SomeName\ProjectName\ with
SomeNameSpace.SomeName.ProjectName.sln and
SomeNameSpace.SomeName.ProjectName.csproj as it's name?
What am I missing, that it seems impossible to achive this in a simple manner?
Create the Project from the New Project VS Window. The settings you need are:
Name: ProjectName
Do NOT create directory for solution
This should create the csproj and sln files in the appropriate directory.
From here, right clic on the project in Solution Explorer -> Rename -> SomeNameSpace.SomeName.ProjectName
This way, the solution reference will be updated too.
Now, rename the solution too, from Solution Explorer.
File menu, Save All. This saves both the project AND the solution.
And I think that's it.
You should in your new project window have it look like this
Please note the highlighted aria is unticked
Ok we have figured it out.
The solution as posted by A. Chiesa was almost right.
The solution, projects and namespaces need to be set.
- Rename the Solution within the "Solution Explorer" for example name it "NameSpace.SomeName.ProjectName"
- Rename the Project within the "Solution Explorer" for example also name it "NameSpace.SomeName.ProjectName"
- Go to the project properties and rename within Application the "Assembly name:" for example also name it "NameSpace.SomeName.ProjectName"
- Go to the project properties and rename within Application the "Default namespace:" for example also name it "NameSpace.SomeName.ProjectName"
Then if you are lucky, you can use Resharper to rename the namespace for all files throughout your project or you have to do it manually (depending on files count can be a very tedious job to do).
That should do it.
Thanks everyone for your input and advice.
Best regard,
Ed
I want to make a backup from the whole project. I also need to rename every backup. I'dont like the way to copy the project folder and rename the folder and the project file.
I've already tried to make it like that:
http://jasonfaulkner.com/VisualStudioExpressProjectBuildBackups.aspx
But it doesn't work, I am always getting the error "Invalid parameters"
Does anyone already tried this?
Thanks
The DPack extension for Visual Studio includes the Solution Backup tool that creates a zip archive of the solution and auto names it.
Manually edit .sln file
This method is entirely aimed at renaming the directory for the project, as viewed in Windows Explorer.
This method does not suffer from the problems in the Remove/add project file method below (references disappearing), but it can result in problems if your project is under source control (see notes below). This is why step 2 (backup) is so important.
1- Close Visual Studio.
2- Create a backup of your .sln file (you can always roll back).
3- Imagine you want to rename directory "Project1" to "Project2".
If not using source control, rename the folder from "Project1" to "Project2" using Windows Explorer.
4- If using source control, rename the folder from "Project1" to "Project2" using the functions supplied by source control. This preserves the history of the file. For example, with TortoiseSVN, right click on the file, select TortoiseSVN .. Rename.
5- In the .sln file, edit all instances of "Project1" to be "Project2", using a text editor like NotePad.
6- Restart Visual Studio, and everything will work as before, but with the project in a different directory.
Alse would recommend TFS, a powerfull tool to do what you pretend. You will be able even to recover previous versions of specific files,if you have any error and you have troubles find it you can see what changes you did since last "check in " etc. There are many options
I had a C# class library project as part of my solution. I later updated the root folder of the project. Since the solution was pointing to the wrong path, I had to "delete" the project and then re-add it.
However, when I add the existing project, it says "The project file \myproject.csproj' has been moved, renamed or is not on your computer".
This is baffling because the .sln file has no reference to the project. (I checked the text contents)
How does VS cache the project with it's old folder path? The solution is version controlled in TFS, but the mappings point to the new folder structure, so it's even more confusing as to where it's trying to get the old folder path from.
Edit: I checked the .csproj file, the .csproj.vspscc and none of them have a path variable in them.
I have also tried deleting the .suo file.
This has been a trouble with Visual Studio for years now. In such a case, deleting the hidden .suo file in the root folder and restart VS will reconstruct a proper .suo file and almost always eliminate the issue.
If you use TFS, take a look at Just TFS' comment in the original post to avoid this problem in the future.
I have a C# project that has multiple folders: Folder1, Folder2.
I added a shortcut in 'Folder1' to an xml file that is already in 'Folder2'. In this case when I compile the project the xml file will I have two copies in the assembly?
You were not clear with your description - did you reference the file with a shortcut, or did you add it to Folder1 by using the VS Solution Explorer and adding an existing item as a link?
The two methods are quite different. If you simply went into the filesystem and added a shortcut, then that is not automatically part of the project unless you specifically add it. And if you did add it, then it obviously can't be compiled, the best you could do is just have it set to No Compile and copy to the output directory.
If you added the file to folder one via the VS solution explorer and added it as a link, then it will be part of the project, and will be included twice, but it will be placed in Folder1 under the bin/debug or bin/release folder upon building. There will be no clash because they are in different folders, and they are not compiled, simply copied to the folder structure under the output directory.
Edit: and it won't be part of the assembly unless you set it to be a Resource or Embedded Resource. If you do that then yes, it will be in the assembly, but under two different resource paths.
In the Properties(context menu) of the selected file in the Solution Explorer change Build Action property to No Compile.