The best way to rename a project in Visual Studio 2008 [duplicate] - c#

This question already has answers here:
How can I rename a project folder from within Visual Studio?
(42 answers)
Closed 8 years ago.
I always find my self in trouble with a lot of namespace or reference errors when trying to rename a project in VS.
This is how I do it: I click on the project and press F2 and rename it.
What procedure do you guys follow?
I used to work in Eclipse, and there I don't have the problems. Maybe it's easy in VS too and it's just me.

Try highlighting the root namespace in one of your files, and then hitting F2 and typing the new one in. This will perform a Refactor->Rename (also available via contextual menu), which should change that root namespace in all your files. Then, setting "Default Namespace" and renaming your project should take care of the rest.

Renaming the assembly should not be an issue, unless you have external projects depending on it. Within the same solution, it will carry on working correctly.

In the properties for the project, I can set "Assembly name" and "Default namespace", I think it's what I've been look for. I assumed that the namespace was automatically renamed also in that proces.
If i'm still missing something, let me know so I can accept your answer.

Related

C# Missing Assembly Even After Adding Reference

Hello I have a question why does I can't import anything from other project even after I add the reference. I tried to create a project for learning best practice by following some tutorial. First I create a console app and name it Prestige Biz later on I notice that I type a wrong project name and wanted to follow the tutorial, so I rename it to Prestige.Biz (I also change the all the namespace in code, folder name, assembly name, and default namespace to Prestige.Biz). After that I create new project for testing named Prestige.BizTest and add reference in testing project to the console app. I can see the reference added, the path to code, and the code in the reference (by double clicking it) all right and good. Then I tried to create an object from Prestige.Biz but I can't. I can't even add using Prestige.Biz all the suggestion give is using Prestige.BizTest. I tried to rebuild everything, reopen the visual studio but nothings work.
I create new project without making typo in project name and it all working fine, but the previous error really bother me. What I did wrong? Am I making a mistke by editing the project designer
Thanks
If it is not useful for you then please don't mark it negative. But I have solve this way.
I was face same issue and solve as below.
If you change project name then you also need to change into project file "Visual C# project file".
Open this file into notepad and change as below highlighted place.
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>your new project name</RootNamespace>
<AssemblyName>**your new project name**</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>

Renaming generated DLL files in VS2013 [duplicate]

This question already has answers here:
change the name of output dll
(4 answers)
Closed 8 years ago.
I have a solution with 5 projects contained within that I have adapted for a new purpose. I have renamed all the project directories and changed all of the filenames within VS2013 as well. My problem is that all of the files generated upon a build still have the old name. Can anyone shed some light on how I might be able to get all the generated files to have a name that I specify when I hit build?
Thanks
The way to do this is the same for all (decently recent) versions of Visual Studio.
Right click on project in Solution Explorer
Click on Properties
Open "Application" left tab
Change the fields Assembly Name and Default Namespace
You would also be interested by this answer and the other answer linked inside : https://stackoverflow.com/a/224788/461444 and you may also want to edit the "AssemblyInfo.cs" file in Properties subfolder of your project.
Also, if project have already been deployed somewhere, I suggest you to remove the old, badly named, assemblies because they can really mess the things on multiple DLL projects.
Go on Properties of your relevant project and change Assembly name.

"microsoft.visualbasic.fileio does not exist" trying to use TextFieldParser

I've seen the above question asked many times on many sites, but I haven't seen an answer that fixed the problem.
The scenario is this...
I am on .NET Framework 4.0, building a C# web application in VisualStudio 2012 Express with the Razor view engine.
I'm trying to use Microsoft.VisualBasic.FileIO.TextFieldParser in my code. From what I've read it is appropriate to do so by adding a project reference to Microsoft.VisualBasic, which I've done, and coding #using Microsoft.VisualBasic; in my view. However when I code...
Microsoft.VisualBasic.FileIO.TextFieldParser parser = new Microsoft.VisualBasic.FileIO.TextFieldParser(new StringReader(xxxxxxxx));
...in the view and rebuild the solution it returns errors: The type or namespace name 'FileIO' does not exist in the namespace 'Microsoft.VisualBasic' (are you missing an assembly reference?)
I know the reference is in the correct project because when I add and remove it I see it come and go from the references folder. I know the code I'm trying to reference exists because I can see it in Object Browser. I've even tried adding the reference using Object Browser instead of through the menus and although it gets added, the results are the same.
The solution it's in is a bit complicated so I tried just creating a test stand alone C# project and I get the same results. I also tried creating a test stand alone Visual Basic project, and sure enough, it works there as advertised. I'm by no means an expert on Visual Studio so I'm guessing that it's just something I'm missing in the configuration, but I'm at a loss to figure it out.
I've spent days on this, so any help anyone could offer would be greatly appreciated.
Right-click on your project and select Add Reference...
In the Reference Manager, expand Assemblies and select Framework. Then check the box for Microsoft.VisualBasic and click OK.
Credit goes to:
https://stackoverflow.com/a/17146200/2530360
I just had the same problem and your question title was more verbose so I figured it should have the answer inside.

Adding reference (e.g by adding "using system.web" ) once for multiple libraries [duplicate]

I am a recently converted VB developer to C#, but there is one thing thus far that I haven't been able to find. In VB when I setup a new project I can specify the namespaces used in the project and add them to the default imports for all classes (so everything automatically has them as if I added "Imports System.Data.OracleClient" to each class). With C# I've found that I'm always typing these in for each new class. Is there a way to setup defaults for projects so it at least appends those to every class file for me automatically?
No there is no way. C# does not support the concept of project level imports or project level namespaces.
The only thing you can do is alter the item template you are using (Class.cs or Code.cs) to have the namespaces you would like. These files are located under the following directory
%ProgramFiles%\Microsoft Visual Studio 9.0\Common7\IDE\itemtemplatescache\CSharp\Code\1033
Under here you should see a Class.zip and Code.zip directory each with a .cs file under them. This is the template file used when you do an "Add New Item" operation in Visual Studio. You can change these to meet your needs and have the default namespaces you'd like.
A slightly easier solution though is adding a per-user code file for the particular project you'd like. Simply create a code file you want to be the template for your application and then place it in the following directory.
C:\Users\YourUserName\Documents\Visual Studio 2008\Templates\ItemTemplates\Visual C#
This file will now show up whenever you do a "Add New Item" operation.
Others have suggested using templates etc. Personally I find it's just not a problem - I type the name of the class that I want to use into Visual Studio, and even if it's not found the "smart tag" (or whatever it's called) icon pops up. I hit Ctrl-. and it adds a using directive for me.
I think ReSharper helps to make this work even better, but it's so automatic for me now that I don't really think about it much any more. (I suspect the difference is that with ReSharper I can hit Alt-Enter at any point in the line and it'll offer the correction, instead of having to have the cursor in the type name itself for Visual Studio.)
With C# 10 this answer has changed.
C# 10 introduces [Global using directives][1]:
Global using directives
You can add the global modifier to any using directive to instruct the compiler that the directive applies to all source files in the compilation. This is typically all source files in a project.
no, there's no my namespaces in C#. I think you can probably accomplish the same thing with project templates or code snippets.
See this post for the answer..
Which, in a nutshell, is adding the usings you want to a template.
I believe you want to start here.

Class Library Intellisense not showing up after adding the dll to the references

In C#, I made a ClassLibrary that has one Namespace and one Class.
I saved it and build it.
in other Projects, when i use it, I add it to my references by browsing to the .dll location.
But The Problem is that its name is not showing up in the Intellisense.
i.e when I: using ... my dll doesn't show ..
I'm Importing the library to a ConsoleApp.
both of the App and the library target Framework is .NET Framework 4.0
and I made their Assembly Version 4.0.0.0 so they're the exact same.
is there a setting or something that I'm missing ?
how can i make it pop up ?
I'm using VS2010 Professional
Thank you for your help
Maybe this be usefull, I was having a similar issue, I have a Web project, add the reference to a Class Library by selecting the project, but if I made a change on the class library, I canĀ“t see that change on the intellisense of the Web Project, after try many things, I see that in the recently added reference, the value of the option "Local Copy" was set "True", then I change it to false and everething works!
I had a similar issue but in my case it was a property on the class. If you go to the file properties and look for a Build Action. Somehow mine was set to Content it had to be set to Compile.
I am using Visual Studio 2013. I hope this helps someone else.
Is the namespace for your assembly different than the namespace for your currently open project? I've had times when the current project and an assembly share the same namespace path the intellisense can mess up.
In general, Visual Studio is pretty good about intellisense generation, especially for C#. But sometimes there are some interesting conditions regarding ambiguities, and especially mixing project types where it just doesn't quite work.
Placing your content in the same namespace makes me wonder if you've actually fixed the problem (it may just be autocompleting the namespace in the currently loaded project rather than the assembly), but if it allows you to continue working, then go with it!
Right click on project on which you add reference of your dll/project select menu project dependancies and select/MarkCheckBox for reference project/dll. then it will work fine.
If the class library project had its name changed after creation, then intellisense may fail finding it due to directory issues, I believe.
I created my class with the generic "ClassLibrary1" or whatever, and then later changed the default namespace, class name, and project name inside of VS2017. I closed VS2017 and changed the directory name to match my default namespace, and then re-associated the project file in VS2017, and then re-added the reference in my main project file.
All seems to be fixed now.

Categories