VS Wizard Template - Change Project solution and directory - c#

I'm writing a Visual Studio Wizard Template using c# on visual studio 2012.
I followed the MSDN steps:
I created a VS template, then I created a Class Library project with a class which implements the IWizard interface, I configured the .vstemplate file and etc...
Now, my target is to write in the RunStarted function code, which does the following:
On the project creation, it copies another existing solution directory from another location to the new project selected location, and then, instead of creating the new project in a new solution, the new project will be added to the copied solution, in a specific "apps" folder, and no new solution will be created.
In the RunStarted method I wrote a simple CopyDirectory code which copies the wanted solution to the $SolutionDirectory$ which I extracted from the ReplacementsDictionary parameter. But now, I don't success to continue and change the new project configuration though it will be generated as a project of the copied solution.
Do you have any idea about this issue?
Thanks!!

You have 2 options:
If you have the DTE \ Solution2 object of the solution, you can use the AddFromFile() method or directly add the project from the template by using AddFromTemplate() method.
The current DTE object can be obtained by the GetService() method:
// Get an instance of the currently running Visual Studio IDE
DTE dte = (DTE)GetService(typeof(DTE));
If you can't get the solution as DTE object, you can edit the .sln file by using XML editing (look in existing .sln file how the projects added).

Related

How can I add a class to my own console app project

I am facing this problem enter image description herewhen trying to add a new class to my project
Can anyone help me please
If you cannot add class to your project using IDE, as a workaround you can do it manually.
Go to your project's directory (where Program.cs is located)
Create new file named Class1.cs (you can give any name)
Go to Visual Studio and see is new class appeared.
If it didn't click on Show All Files, see your class, right click on it and choose Include in project
But this is obviously not a long term solution. Try repairing your Visual Studio using Visual Studio Installer

VSIX and item templates

So I'm having some trouble creating an item template and would like some help.
What I'm trying to do:
Create a template that adds 3 files. A Class.cs and two config files in the location "./Config/Acc/Config.xml" and "./Config/Prod/Config.xml".
I've managed to create the template through the wizard and editing the resulting files, but I would like an easy method of distributing the template on my teams TFS.
From some googling it seems that I should use A VSIX project to deply this easily. Problem is that I can't get it to compile. I have 2 projects: VSIXproject and ItemTemplateProject. I've set the assembly info on VSIX project to use the ItemTemplateProject and I've modified my Class.cs, but when I compile, visual studio doesn't know how to handle the Class.cs file.
What am I doing wrong? Is there a better way of including my ItemTemplate so that anyone who pulls the repo can use it?
The template project (a project that only contains Visual Studio project templates or item templates) is only used to be able to work with templates. Its output (say [myproject].dll) is not important (the project type may be C# but it's irrelevant) and you will only distribute the .vsix file in the end.
Files (.vstemplate files and any other files) in this project are like "static" files. They will also ultimately be included into the .vsix file output during build.
So, to ensure this files (.cs or other) are "static", you must make sure they have their action set to None (for example), not Compile.

Add programmatically Visual Studio Solution and Projects

I am trying to generate a Visual Studio 2010 solution and add VS 2010 projects from custom templates!
My requirement:
1. Generate a VisualStudio Solution 2010, Save it to a folder, add VisualSTudio Project from my own templates (I have 3 different templates: ClassLibrary,WinForms ,WCFService)
My issue:
I implemented something that is working half a way!
Solution is created correctly but the content of the ".sln" file is very poor! No project reference is added >
In the root folder, it creates a Solution also for the C# Project, which I do not want. I want only the MainSolution file. (In my case "TestSolution.sln"). How can I stop creating a solutionfile for each project created?
Below the source code I use:
//for The solution:
//adding a project
Am I using the wrong interfaces?
Why the vs2010Solution.AddFromTemplate(..) returns null after the call, but no exception is thrown? Also the Project is created correctly in the folderstructure! But at runtime I can't check the list of projects "vs2010Solution.Projects" as it is null! (After correctly adding a project). I need the Project added because I need to add some references programmatically, which I try to do in the next line, but it doesn't work because vs2010Project is null).
So I am trying to wrap the VisualStudio 2010 automation model, to create a solution and add projects! But is not really working! Do I need to cast EnvDTE.Project to "VSLangProj.Project" at some point? I want to create a clean wrapper for VS2010, after that one for VS 2012!
Any help is much appreciated.
See the several articles of the section "Articles about automating project creation" on my web site:
http://www.visualstudioextensibility.com/articles/add-ins/
They explain why AddFromTemplate method returns null, how to create a solution, a project, a project inside a solution folder, a project item, etc.

Can I tell Visual Studio to kindly keep its ugly meta files away from my source directory?

Short version: I want Visual Studio 2010 to save the solution and project files to the default "My Documents" directory, while regarding my actual project directory on Dropbox as the place to put source files.
I know I can "Add Existing Item" from the project menu, but that's hardly an acceptable solution as I have to manually create absolutely every file I'm to work with in VS from explorer. I've tried adding my project folder to the project, but that just resulted in VS lying to my face:
Is it possible to actually separate Visual Studio's fugly meta files from my project directory? If not, what would be the best workaround?
I might have to do my C# in Vim because of this...
NOTE: I know C++ projects has the "Add Filter" function, which appears to do almost exactly what I want, but I'm working with C#.
Workaround
Create a symlink from the actual project folder in Dropbox to Visual Studio's project folder, e.g:
C:\Users\tomas>mklink /J "...\Visual Studio 2010\Projects\Testing\Journal\journal" "...\Dropbox\Projects\cs_testing\journal"
Junction created for ...\Visual Studio 2010\Projects\Testing\Journal\journal > ...\Dropbox\Projects\cs_testing\journal
Then add the symlink to the project as an "External Item". Now Visual Studio thinks it's being devious and adding all new files to its own project directory, but they are actually ending up in my Dropbox.
Drawbacks
Every item added to the project must be put in the symlink subfolder.
Items automatically add themselves to the namespace "<project>.<subfolder>.*", so on my case an added class was automatically called Journal.journal.JournalForm.
It's tedious to do this for every project.
There are probably more, but I just discovered this workaround. I'll edit this answer later if necessary.

VS 2008 - Star Team and multi project solution?

I have a project which is under source control via Star Team in VS 2008. I added another project to my solution for an installer, configured it, tested it, etc. Now, when I go to check in my solution with the new installer, I get the following warning:
The project that you are attempting to add to source control may cause other source control users to have difficulty opening this solution or getting newer versions of it. To avoid this problem, add the project from a location below the binding root of the other source controlled projects in the solution.
There are with options to Continue or Cancel.
My project directory looks like this:
/Proj1/
Proj1.sln
/Proj1/
.cs files
.csproj
/bin/, etc
/Proj1_Installer/
Proj1_Installer.vdproj
/Debug/
/Release/
Is there something fundamental I'm missing?
The files for the new solution should be in the same location as the projects you already have from source control. For example if you have existing code from source control
Source\
Project1\
program.cs
Proejct2\
program.cs
then you need to put your new project in the same folder and project1 and project2
Source\
Project1\
program.cs
Proejct2\
program.cs
NewProject\
"add the project from a location below the binding root of the other source controlled projects in the solution" If you decide to add it to the "MyProjects" folder on your drive, then others won't be able to get it from source control.
I suggest if this is how your physical folder structure actually is, verify the solution file using notepad and check the paths. Maybe it's referencing it using
..\..\Path1\Path2
instead of
.\Path2
My problem was that my debug and resource folders were being put into source control. Visual studio wants to generate these every time the project runs, so they shouldn't be placed in SC.

Categories

Resources