Visual Studio - Programmatically configure solution for source control - c#

I am in the process of creating a Wizard to help my organization auto create a base project for all applications. The idea is that a programmer can enter a project name, a few other basics and the process will create some projects, add other project from source control, configure IIS, etc...
A lot of the work is done by simply using project templates and the IWizard interface for some of the more complicated operations. What I am trying to do is this, once all of the projects are auto created, I am creating a workspace and automatically moving all of the files under source control. I am also doing things like adding common projects, setting up some special settings in IIS, etc... The problem is that the solution file, although it is under source control, is not actually configured to use source control.
Anyone have an idea on how to programmatically configure a solution so that it is part of source control and ready to use? I've run into a brick wall and can't seem to get any further. BTW: In case a didn't make it clear, I'm essentially trying to do the same in code as right clicking on a project and selecting "Add Solution to Source Control."
Like I've said, I've got most of the issues solved. Just this last one is giving me fits...
The important facts:
Windows XP
VS 2008
TFS
Using Microsoft.TeamFoundation objects....

Can you handle this through the Visual Studio extensibility framework? EnvDTE basically provides access to anything you can do interactively...

I just did what you said while recording a Macro; Looks like:
DTE.Windows.Item(Constants.vsWindowKindSolutionExplorer).Activate()
DTE.ActiveWindow.Object.GetItem("CLSTestSolution").Select(vsUISelectionType.vsUISelectionTypeSelect)
DTE.ExecuteCommand("File.TfsAddSolutionToSourceControl")
Perhaps you can start there?

Related

Visual Studio 2013 only builds HTML changes, not C# changes

I am building a personal website using asp.NET's webforms in visual studio 2013 express for web and am following this tutorial:
http://www.asp.net/web-forms/overview/getting-started/getting-started-with-aspnet-45-web-forms/introduction-and-overview
My page is structured exactly the same as in the website, I have changed some minor stuff to make it my own but the structure in terms of the C# classes and how the interact with the HTML are exactly the same.
I got to section 5 of the tutorial "Display Data Items and Details" and everything was working fine. I've used git a lot in the past so I decided to create a repository for this project so I can access it at work if I feel like.
Suddenly now when I make changes to the C# classes it won't build. It's even stranger because I if I make a change on an HTML file the change is built. In section 3 of the tutorial we learnt how to make the 'product' classes which are displayed on the products page. If I want to change one of the product names for example, when I build the change is not there. Simultaneously I went and changed some info in the HTML for the contact page, IT CHANGES when I build. Why wont the C# changes take effect when I build any more?
I am relatively new to both asp.NET and visual studio. The HTML changes when I build and the C# does not. When I change either I can see in solution explorer that there is a red tick for pending changes. Why would only the HTML pending change be included in the build and not the C#? How do I ensure that the build is actually building the version I see in my editor window?
EDIT
I do not know if I found the original cause but I found a solution/workaround. I realized that the classes mentioned above were grabbed by the html page from the page's database. The .mdf file for the solution was not being rebuilt whenever I cleaned and built so I physically deleted it and rebuilt the solution and voilla my C# changes occurred. I am still fairly new to this whole thing, can someone explain what the .mdf file does and why it wasn't being rebuilt?
Check your .cs files properties on the properties window in visual studio to make sure their Build Action is set to "Compile", Things that are not set to "Compile" do not get compiled. How MSBuild treats project items depends entirely on their build action. CS files default to "Compile" when you make them, but if you changed them yourself that would be why it doesn't update. Also CS files placed in the App_Start folder default to "Content" and they are compiled by ASP.Net when the Application Starts, so if you changed something in App_Start you need to reset the site.
Not exactly sure what is the problem, but I would do a right mouse click on the solution in Solution Explorer->Clean Solution, then do another build and see if that helps.

Add Visual Studio solution to existing solution in Visual Studio

I wrote an application in Visual Studio C# 2010, that I would like to import into another existing Visual Studio C# 2010 Application. How would I go about doing this?
For instance, I'd like to import the project into another, and basically copy/paste the interface from the application into a tabpage on a tab control I have.
Any assistance or advice on how to do this is greatly appreciated!
You should be able to copy the physical files using windows from the existing solution location to the new solution location.
Then once the copy is complete open Visual studio and tell it you want to add an existing project. Navigate to the folder where the files are on the filesystem and open the project file.
Once you save the solution it should from that point forward have the new projects in the new solution.
There are several ways to achieve this - Copy & Paste being one of them (but the least beautiful of course). A more promising one is the following:
Wrap the user interface you want to share in a User Control in the existing project. Also include the code behind logic in this user control. Include the user control in the project and make sure that everything works before continuing.
Add the existing project to the new solution. It is advised that you create a hierarchical structure in the file system for the solution so that all projects in the solution are located under a directory.
Reference the project from the project that wants to access the user interface. As the projects are in the same solution, you can add a project reference. This asserts that the projects are built together.
Place the user control on the tab page.
As an alternative, you can also pass on adding the project to the solution but only create a user control and add a binary reference from the other project.

Visual Studio add in that alphabetizes values in a resource file

I want to make a visual studio's add in that has the ability to sort resource files alphabetically every time someone edits a resource file. I'm not looking for a solution, but I have never used the Visual Studio sdk before. I simple want to know if anyone that has experience with the Visual Studio sdk may know if this is possible? Also any suggestions on how to start making an addin are appreciated.
If you have never used visual studio extensibility, I recommend you this page:
Make a solution notebook tool window
There is some useful information about how to interact with visual studio for saving data in sln and suo files, and also you can find information about some attributes you can use to tell visual studio what your package (or plugin) needs to do.
It's a general knowledge thing although, not directly related to what you want to do.
this link is about how to listen to some specific events visual studio fires, it shows you general way of creating listeners in your plugin
this one is actually about what you need to do (it tells you how to catch the event fired before visual studio saves a file)
and the most important one: the source code for creating a custom source control for visual studio, that's where I found most of the info I needed to understand visual studio extensibility
with all these links you should get something to start with, and of course you have the official msdn documentation about extending visual studio
What you'll need to do is creating a plugin that will listen to events fired when an item is about to be saved in visual studio. I don't think there is a specific event for resx files, so you'll probably have to test which file is saved, but that should be all.
Once you have the item, you can find the physical file and sort it.
Another thing, I found out that the events declared in the DTE object don't really work (at least for me it didn't), that's why I recommend you to implement the listener pattern to catch the events you need.
Hope this helps
I actually did exactly that.
You can find the source code for the extension in GitHub. It shows you how the get handles for files from the Solution Explorer, add context menu actions, write to the output menu, etc..

Where can I find the implementation for IVCWizCtlUI

Background:
I have an visual studio C++ custom project template to create a custom solution. When we say new project and select this custom template, it would ask for an xml file and create a visual c++ solution, substituting values from the xml file to the template files.
What am trying to do now?
I wanted to automate this process, (no user intervention to open visual studio and select the custom template). Infact to use the component in C#. This component has a dependency with visual studio wizard as shown in sample javascript
Difficulties faced?
The xml parser is a com component, which takes visual studio wizard as a parameter. Only if i set this properly, i can proceed further. The wizard is basically implements the below interface.
http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.vswizard.ivcwizctlui_members(v=VS.90).aspx
Not sure how to access this wizard in C#.
Current Javascript code:
var aConverter = new ActiveXObject("NAMESPACE.MYParser");
//Problem: Not sure how to set this value, when "NAMESPACE.MYParser" used in C#
aConverter.Wizard = window.external;
aConverter.Filename = xmlfile;
//This method if called from C# without setting "aConverter.Wizard" throws exception
aConverter.ParseMyXML();
var value = aConverter.Someproperty;
Prior research:
I tried to use dte.LaunchWizard, but still i get an UI popped up, which i need to avoid. LaunchWizard not a good way for me, as i wanted direct control in C# for "NAMESPACE.MYParser"
It may be not exactly the same direction as you want to go, but have you considered using CMake(open source) for that?
CMake is a tool for automatically setting up code-projects/toolsets on different plattforms and IDEs. CMake can also generate VisualStudio solutions, so all you would have to do is set up your CMake config files, and just generate the solution. You can also incorporate parameters, so that the user is able to costumize the project to be generated even further.
It is a great tool, runs on most platforms and there is also an easy to use GUI available. Check it out: http://www.cmake.org/

Add-in for Visual Studio for project file editing (csproj)

Do you know an add-in for visual studio which adds properties for C# projects?
csproj file format is very powerful but only small amount of options can be changed through the standard properties page. For instance, I want to have several configurations and each of them should include it's own references. Or I just want to change the type of project from winforms to wpf or other one. In order to do stuff like that developer has to edit csproj by hands in text editor instead of using properties.
If you know that such add-in doesn't exist, do you think that it could be popular on codeplex? or only small amount of developers realy need it? what is your opinion?
How is it going?
To edit project files inside of Visual Studio I use PowerCommands, but those things you can change "using properties" are those in Project Menu -> [Project Name] Properties. What PowerCommands does (among other things...) is allow you to easily edit the XML of a project opened inside Visual Studio so you get all the benefits of using Visual Studio to edit XML. Makes sense?
XML is hierarchical, so hardly you can fit it comfortably on a property list better than on a text editor.
About "I want to have several configurations and each of them should include it's own references", try creating templates for your projects, take a look there: Visual Studio Templates.
So... you are looking for addins at codeplex? why not take a look at http://visualstudiogallery.msdn.microsoft.com there are free and paid addins, an some form codeplex too. While you are on it, look for "Productivity Power Tools", "VSCommands 2010", "AllMargins" and "VS10x Code Map". I use them all, and they are certainly worth a look. [Hmmm... I also use CodeRush, you can get CodeRush Xpress for free from http://www.devexpress.com ;)]
Hope of being of help.
A little late to the table but I wanted to remove VSCommands 2010 because all I use it for really is the edit project file and I don't like to just have extensions hanging around if I am not using them. I discovered from this blog:
http://blogs.msdn.com/b/habibh/archive/2009/07/01/the-quickest-way-to-edit-a-visual-studio-project-file.aspx
"There is a quick and easy way of editing your Visual Studio project file. When a project is "unloaded", either because you explicitly chose to unload the project using the "Unload Project" command or Visual Studio failed to load the project for some reason (e.g. project upgrade failed), you can right click on the project in Solution Explorer and select the "Edit " command, as shown below."
It works like a charm!

Categories