Read information from project designer fields - c#

In my Visual Studio solution, there are two projects. The first project is a web application. The second project contains tests, it references the first project.
In the web app's project designer, under the 'web' tab, is a field 'project URL'. At the moment, this happens to be completed:
http://localhost:8080/shop
How can I access the value of this field from my code? (in particular the test project)

The short answer… you can’t and shouldn't. This value is just a user preference setting for Visual Studio and has nothing to do with your code or the compiler.
Having said that, the value is stored in the ProjectName.csproj.user file (which is just an xml file) so you could theoretically open the file from within your code and get the value that way. I’m not sure when this would ever be a good idea though.

Related

Item Templates Sometimes Missing in Visual Studio 2017

Using Visual Studio 2017, sometimes new item templates are missing, and it seems to be tied to the particular project to which I'm trying to add an item.
Although both show up as "C#" projects...
...in "Logging", for WPF items, I have only UserControl (WPF) as an option:
However, in "SanityCheck", I have a much-more-full list of WPF options:
The only difference I can easily see so far is that the one ("Logging") is a Class Library project while the other ("SanityCheck") is a Windows Application project. However, changing Logging to Windows Application doesn't make more options available, and I ought to be able to create a Window in a Class Library, right?
I also noticed that Logging didn't contain all the same references as SanityCheck, so I added all the ones that seemed possibly-related, and that also didn't make any difference in the set of templates available.
So how do I get my Logging project to let me add a WPF Window?
Thanks to a comment from ASh and the list referred to from this question, I determined that the cause was a missing <ProjectTypeGuids> block in the Logging.csproj file. I copied the one from the SanityCheck.csproj file and now all the C# WPF templates are available. So far I haven't encountered any negative side-effects to this solution. Time will tell.

Accessing properties of a project using EnvDTE

I'm writing a visual studio add-in to automate some of our BizTalk related tasks.
I'd like to be able to access the property values of a project (not what shows in the default 'Properties' pane. The properties shown in a window if you right click on the project and select 'properties' from the context menu.)
Specifically I'd like to get/set the application it deploys to, assembly signing, etc. The rest of the add-in is already working.
Thanks!
I'm not sure it includes deploys/assembly signing and it's hard to give a complete sample as there is lots of supporting code, but you can start from IVsSolutionBuildManager.FindActiveProjectCfg, cast the result to IVsProjectCfg2 and enumerate OutputGroups.

Can't change a project's Default Namespace in Visual Studio 2013

I have a solution that includes various C# projects, and I just now noticed that I can't change the default namespace on any of them.
When I go to Properties --> Application on any of the project and change the "Default Namespace" field, a fatal error dialog pops up that says:
exception of type 'system.runtime.interopservices.externalexception' was thrown
At this point Visual Studio becomes unusable, as I can't close it or leave the screen, every click or button combination I press makes the same dialog pop up. The only thing I can do is terminate VS with the task manager.
I got around it by just renaming the <RootNamespace> node in the .csproj file
Maybe you should try to do this in another way:
Ctrl-H - Find: PreviousNameSpaceName Replace: NewNamespaceName
You can also right click the namespace in code and Refactor->Rename.
What is more: you can change the names of your projects, solutions, directories - etc. Namespaces, when adding new files, are generated using these names in fact.
I had to investigate the issue in our company and I found another workaround in our case. So I think it make sense to add it here.
Possible Solution
Check if you have more than one suo-File for the project/solution and delete the one which doesn't has the ".v12.suo" naming (better delete both)
Story behind:
We still have two Visual Studio installed (2010 and 2013) and some of our developer worked recently on 2010. So they had on the file system a regular ".suo"-File. Afterwards (some weeks later) they started to use 2013 (which created a ".v12.suo"-File).
We renamed both suo files, started VS2013 (which created the v12.suo) and were able to rename the namespace without a crash. In addition we had this issue not on all solutions. I didn't see yet a pattern, but in our case it happened mostly on solution with at least two projects and referenced project-libraries.

Visual Studio 2010 Intellisense

When using Visual Studio 2010, I open an aspx and cs file to edit. (I have not created a project. I am simply opening one aspx file and one cs file from my web directory to edit.) The intellisense will not detect System.Web or a large variety of others. In fact, only basic resources seem available. Is there a way to correct this?
As you are not in a project, you lack much of the context that would permit full intellisense support. VS has no idea what assemblies are included, and does not have imports from the web.config.
Remember that Intellisense tries to only present you with code completions that actually apply in the current build configuration. Without assemblies referenced, it can't guess that you have anything at all in, say, System.Web.
the Intellisense pretty much based on the content of the "using" clauses you have in the beginning of your file. It runs based on what you have already typed against a list o possible functions contained on the "used" assemblies.
For example, if you want intelisense to have access to the Convert function you need to use the System assembly. Without it, intelisense wont know the function exists

How to automatically convert VS2003 classes to partial Designer.cs files?

I'm upgrading a project from Visual Studio 2003 to 2008 and wish to automatically generate XXX.Designer.cs files and update the corresponding XXX.cs original one.
Any automatic way to do it?
UPDATE: I'm referring to WinForms. Of course, I know the old style works but i'm looking for a way to go to the new style without doing it by hand.
There is a macro out there floating that does this. I have used it and it works great. Start by looking at Nathan Jones Blog. If you dont have much luck then download a zip of the macro source (I posted) from VSCONVERT - PasteBin
The original classes will continue to work - even with the Visual Studio designer. The code the VS puts in the Designer classes is simply meant to remove the designer "noise" into a separate file so you can focus on the non-visual code in your class.
Once you migrate the project to VS2008 using the wizard, you can open up your forms in VS and continue to edit them just like you did before. Any new forms that you create will get Designer backer files.
We had this problem.
Basically the designer file should contain nothing but a set of object declarations (i.e. the objects on the form) and the InitializeComponent() call. If you've done any fancy work on your constructor that might be there too.
Simply create a file called MyForm.Designer.cs and add it to the project. VS2008 will automatically place it underneath MyForm.cs. From there, if you create the partial class heading and the namespace, then copy across all the declarations and Initializecomponent call into the designer file, then it will work.
But because if you had to, people would edit initializecomponent and also edit the default constructor, VS2005 and 2008 couldn't automatically upgrade these files as all sorts of strange things might occur. I guess from a project point of view, what benefit do you think your working code will derive from the separation?
I'm not sure I understand, but I'll make a guess.
Was this an ASP.NET project in VS2003? Did it have .Designer.cs files in it? Is it the case that you've done an upgrade but you find that you have no .Designer.cs files now?
If so - you may have inadvertently changed your Web Application Project into a Web Site "project". This sort of "project" was introduced in VS2005, so you would not have seen it yet. These aren't real projects (no .csproj file), and they have many other differences.
Otherwise, if your project didn't used to have .Designer.cs files, then why do you want them now?
In general, the way to create designer files is to open the file in a designer, wait a few moments for the designer to finish what it's doing (updating the screen, etc); and then saving the file. You might possibly have to "touch" the original in order to get the designer to reevaluate things.

Categories

Resources