How do I add a folder to a program's namespace? - c#

I recently converted a Visual Studio 2006 project up to Visual Studio 2010. The conversion went over fine, but somewhere along the line the namespace got corrupted, and as a result, parts of the codebase are throwing errors (because the objects they're referencing, etc. are no longer being imported).
I can manually locate the folder with the relevant files, but can't seem to reference the file with using clauses (or I'm botching using entirely). Is there some function in visual studio I can use to import the requisite files directly?

For physical files you can click the Show All Files button at the top of the solution explorer, then locating the folder, right click and choose Include in Project.

if you can get Resharper installed, it will try to hint you the namespace. if upgrade missed to add some files, then you should add them manually and recompile. i am not sure if you can requisite the files directly

The using directive has nothing to do with the folder where the file is located, it is only depending on the name after the "namespace" keyword inside each file.
In some projects people name their namespaces similar to the folder structure but to the c# compiler that is just a coincidence.

Related

Visual Studio Extension, dll deployment and locking [C#, VSIX]

I need some help using CodeAnalysisCSharp in my VSIX project.
The issue I'm currently having is that the necessary dlls are not "deployed" when installing the extension. I've had to manually copy/paste these files to the C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE folder, for it to "work".
System.Numerics.Vectors.dll
System.Runtime.CompilerServices.Unsafe.dll
System.Memory.dll
Microsoft.CodeAnalysis.dll
Microsoft.CodeAnalysis.CSharp.dll
I have created an extension project and added a custom command. This command should be able to use the CodeAnalysisCSharp to navigate the syntax tree of a C# file.
I'd very much like for the installer file (.vsix) to be able to deploy the dll dependencies, just like you'd expect it to, I just don't know how or where to look to make this happen.
Thanks in advance.
I found out that if you use the vsixmanifest file to add assets, and give it a sub folder, it doesn't get packaged correctlty. The files will be copied correctly, but the reference to the dlls are not correct, so you get a "dll not found" exception.
In general the vsixmanifest designer, seems to be riddled with quirks where you need to edit the xml code to be sure that the values are set correctly.

Get Latest on Solution within Visual Studio gets a lot of unnecessary files

When starting out with a clean environment (nothing downloaded yet) and opening a solution for the first time through the Source Control Explorer in Visual Studio, all the necessary files for the solution are downloaded. Meaning i can compile the solution without any problems.
Then, in Visual Studio, when I do a right-mouse click on the solution in the Solution Explorer and do a "Get Latest", a whole bunch of additional files are downloaded that are part of my TFS tree. These files are not referenced by the solution. Does anybody have any idea why these files are downloaded?
I'm aware of another issue where opening an .sln file will download all the files within its root and subfolders, but that already happens when opening the .sln file through the Source Control explorer. In this particular case the sln file is located in its own subdirectory so this doesn't apply.
I'm would be interested to hear from anybody that has experienced the same thing and has any idea on why all these additional files are downloaded from the TFS tree although they are not referenced by the .sln file and its underlying projects.
I would assume that when you do a Get Latest Version within Solution Explorer, under the covers it is performing the operation on the folder that contains the solution and therefore it will pull down any files missing from your local workspace.
If you have items in the solution folder that you don't want to bring down to your local machine then you should use cloaking, explicit mappings and non-recursive mappings to limit what is mapped to your workspace.
2 = Cloaked, 5 = Non-recursive
Optimize your workspace

Move VC# Project And Maintain Links

How do you move a Visual Studio C# project and maintain the linked files?
For example;
I have a VC# Project that sits in folder: A/V2013_Project.
This VC# Project links to files A/Image/a.png this is because we have many other projects that use this file also.
I want to move my project to A/Release/V2013_Project. Ie move the project to a sub-folder.
I'm not renaming anything in the new project, not changing anything else except for the location of the project.
When I move the project all my links fail (theres more than 50) and most of my references fail. By fail, I mean they no longer point to the file. Within the newly moved VC# project; when I click on a linked file VC# displays an error:
Cannot find the file A/Image/a.png. It may have been moved or deleted.
But this file was never moved. Its still in exactly the same place.
How can I move a VC# project and maintain the links and references? Are there any 3rd party addons that can do this?
Edit: Using wintermute's advice; the links are indeed relative and not absolute. For example;
<Resource Include="..\..\Resources\Other\Images\TOOLBAR_close.png">
<Link>Resources\Other\Images\TOOLBAR_close.png</Link>
</Resource>
Any ideas how I can make links absolute in VC#?
It depends on how the file is linked. It isn't clear from your question.
Some files are references by the .csproj file. Close Visual Studio down (just to be sure) and open the .csproj file with Notepad or some other text editor. See if the files you're talking about are referenced there. If so, add the text "..\" in front of each file name, indicating they are one directory higher up, relative to the project location.
Some files are referenced in the .resx file(s). In this case Visual Studio should have included the name of the .resx file as part of the error message. This can be fixed using Visual Studio's editor. Double-click on the error message and it should open the .resx file with the file reference that is in error as the selected line. Again, add "..\" in front of the file name.
You say you have 50 references. Hopefully this means you can search-and-replace to add the "..\" text to the relevant file names.
Edit:
You posted an edit to your question, showing this line:
<Resource Include="..\..\Resources\Other\Images\TOOLBAR_close.png">
If you really want to make this absolute, then just do it.
<Resource Include="D:\Merlinia\Trunk-Debug\Add-Ons\Picture Editor\VS2012 projects\PictureEditor\Resources\Other\Images\TOOLBAR_close.png">
But as I mention in a comment on your question, make sure this is the best way to fix the problem.

C# can't find properties file, how do I repair this?

I had a Properties file called RecentFileList within my Visual Studio 2012 project and I removed it. I believe it was a .settings file. Now when I run my setup project, it is trying to copy files that it shouldn't care about and it's bombing out as a result. I get 3 errors (-1007 -6271 and -6103), all related to the same missing file.
-6103: Could not find file "C:\Users\Charles\Documents\Visual Studio 2012\Projects\RallyCourses\RallyCourseDesigner\bin\Debug\Properties\RecentFileList.Designer.cs
What file do I need to edit to get rid of the reference to this file? I tried searching for RecentFileList.Designer.cs, but can't find it.
The offending files in my situation were trying to be installed by the installer, but I had removed them from the main project. Within the SetUp project, there is a section Specify Application Data -> Files. I found the files in the Properties section there, removed them, and things are working now...

Changing The Name Of A C# Project Folder?

I have a main project directory with the following contents:
SubDirectory (Directory)
Project.sln (Solution File)
When I try manually changing SubDirectory's name in my Windows explorer, I get errors when I open the solution file. How can I rename this directory without affecting my solution?
Thanks!
Rename it in Visual studio, or edit the .csproj/.sln file with a text editor and fix the refrences.
Open the solution file in a text editor and rename all references to the old folder.
Open up the .sln file in notepad. You'll see a line like this:
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "myproject", "myproject\myproject.csproj", "{DF81752F-37EE-4F4E-BC22-B09C8D05ED78}"
EndProject
If you want to rename the folder from myproject to newproject, you can change myproject\myproject.csproj to newproject\myproject.csproj (or whatever).
Change the name in SolutionExplorer.. it will work fine..
However it doesn't gurantee problem with Source Control or TFS you will need to resolve them manually
Your solution has the paths to your project files embedded in it, which includes the folder name. If you want to rename the folder, you have three options:
Close the solution. Rename the folder, then reopen the solution. The projects will show up as gray, and you'll need to click each one and locate the project file in the Properties window. Note that this may remove project references, but it may not. This is what I would suggest.
Open the solution and remove the project(s) within that directory. Note that this will remove any project references from any other projects that reference the project(s) that you're removing. Rename the folder, then add the project (and any project references) back.
Close the solution. Rename the folder, then open the .sln file in Notepad (or some other text editor) and fix the paths manually. This will preserve any project references.
When I have done it, I manually change it, then open the solution. You will get an error about not being able to find the project file, just choose to locate it, and it will re-map it. If you are using VSS, make sure everything is checked in first.
There are probably paths in project/solution related files that contain the old directory name. You'll either have to update those manually or find a way to rename the project from within Visual Studio.
This might help you rename the project:
http://msdn.microsoft.com/en-us/library/3e92t91t%28v=VS.90%29.aspx
In Visual Studio solution explorer,
edit the project properties to change
the assembly name, namespaces etc.
etc. to what you want.
Rename the top
Project nodes in VS solution explorer.
Shut Visual Studio down.
Open Windows explorer and rename your
folders and .csproj files to what you
want.
With a text editor and NOT Visual
Studio, open up the
sln file,
the .csproj files and
anything else you've renamed.
do a
Find & Replace looking for the old project strings, filenames,
namespaces (if required - I suggest
you leave that bit for when all has
been transitioned) and replacing them
as required.
I'm suggesting you'll
need to be selective because I don't
know how you've named your projects
and .csproj files ;-)
Once you've done all that, quit your
text editor and try opening up your
.sln file again.
Do a Rebuild the first time to remove any artifacts from the old configuration/naming.
HTH

Categories