|
I have developed a custom wizard with checkbox on it. My requirement is that if checkbox is checked then add a project otherwise don't. I've tried with the following xml but it didn't work for me to get the value of checkbox that user chooses.
<Argument Name="AddProject" Type="System.Boolean"> <ValueProvider Type="Evaluator" Expression="false" /> </Argument>
And in the action xml i've following
<GatheringServiceData> <Wizard xmlns="http://schemas.microsoft.com/pag/gax-wizards" SchemaVersion="1.0"> <Pages> <Page Type="TestGP.CustomWizardPages.AppWizard, TestGP" /> </Pages> </Wizard> </GatheringServiceData> <Actions> <Action Name="AddProjectAction1" Type="TestGP.Actions.WizardAction, TestGP"> <Input Name="AddProjectArg" RecipeArgument="AddProject" /> </Action> </Actions>
I've defined RecipeArgument in AppWizard class as
[RecipeArgument] public bool AddProject { set { this.chkAddProject.Checked = value; } }
And in the WizardAction class i've
[Input] public bool AddProjectArg { get { return addProjectArg; } set { addProjectArg = value; } } private bool addProjectArg;
In execute method i'm always getting False (default value). Can anyone help me out? Its kind of urgent.
Thanks
Azeem Faraz.
|
| Azeem Fraz Wednesday, August 15, 2007 1:14 PM |
Hi,
I figured this out. Solution is to set the value back to DictionaryService when user changes the value of checkbox. Following is the code that you need to put in checkbox_changed event.
IDictionaryService dictionaryService = GetService(typeof(IDictionaryService)) as IDictionaryService; dictionaryService.SetValue("AddProject", this.chkAddProject.Checked);
Now i've another issue to resolve. I want to either include the project based on the checkbox or exclude it from the solution at runtime. Like if my checkbox says "Add Console Application" and if user checks the checkbox, I want to add a console application with the references of other projects. I've added Console Application Template under the Template/Solutions/Projects folder.
Can anyone guide me?
Thanks.
Azeem Faraz
|
| Azeem Fraz Wednesday, August 15, 2007 1:31 PM |
Try to Combine the IConfigurationService's BasePath with your relative template location (Templates\Solutions\Projects\MyProject.vstemplate).
IConfigurationService confService = GetService(typeof(IConfigurationService)) as IConfigurationService; string templateFullPath = Path.Combine(confService.BasePath, "Templates\Solutions\Projects\MyProject.vstemplate");
-Adrian
|
| Adrian Alonso Wednesday, August 15, 2007 9:28 PM |
Thanks for replying. I used "Web Application Project" instead of VS2005 website. Web Application Project is provided to support the same structure as in VS2003.
http://msdn2.microsoft.com/en-us/asp.net/Aa336618.aspx
I can do what what i wanted to do with it.
Thanks.
Azeem Faraz
|
| Azeem Fraz Thursday, August 16, 2007 6:39 PM |
Hi,
I figured this out. Solution is to set the value back to DictionaryService when user changes the value of checkbox. Following is the code that you need to put in checkbox_changed event.
IDictionaryService dictionaryService = GetService(typeof(IDictionaryService)) as IDictionaryService; dictionaryService.SetValue("AddProject", this.chkAddProject.Checked);
Now i've another issue to resolve. I want to either include the project based on the checkbox or exclude it from the solution at runtime. Like if my checkbox says "Add Console Application" and if user checks the checkbox, I want to add a console application with the references of other projects. I've added Console Application Template under the Template/Solutions/Projects folder.
Can anyone guide me?
Thanks.
Azeem Faraz
|
| Azeem Fraz Wednesday, August 15, 2007 1:31 PM |
Hi Azeem, try to use the IDictionaryService to set the argument value when the checkbox value changes. For example:
private void checkBox1_CheckedChanged(object sender, EventArgs e) { IDictionaryService dictionaryService = (IDictionaryService)GetService(typeof(IDictionaryService)); dictionaryService.SetValue("AddProject", checkBox1.Checked); }
That should set the "AddProject" argument value.
-Adrian
|
| Adrian Alonso Wednesday, August 15, 2007 1:32 PM |
Hi, try to use the dte.Solution.AddFromTemplate(...) method in order to add dinamically the project template from your custom action. And ir order to add a project a reference you have to cast the project.Object to a VSProject and use the References list. For example: VSProject vsProject = project.Object as VSProject; vsProject.References.AddProject(projectReference); HTH and don't be late for a few seconds this time!  -Adrian |
| Adrian Alonso Wednesday, August 15, 2007 1:50 PM |
Thanks Adrian, i'll try not to be late  I didn't try this yet, i'll do it and will let you know. I got one question regarding this. Can I add a project to a specific solution folder like the way you mentioned? And can I set Project Name for that new project as we do in ProjectTemplateLink? There is another question as well (sorry i'm questioning a lot  but i think thats why we have this forum  ). I have added a website project that is FileSystem based. Can I make its port static instead of dynamic while adding it in the solution? Thanks. Azeem Faraz. |
| Azeem Fraz Wednesday, August 15, 2007 2:11 PM |
You are welcome! My answers:
1) Can I add a project to a specific solution folder like the way you mentioned? yes, this snippet should be enough:
SolutionFolder slnFolder = (SolutionFolder)project.Object; slnFolder.AddFromTemplate(this.Template, this.DestinationFolder, this.ItemName);
2) You should be able to set the project name setting the Property through the Project.Properties collection.
3) You can include the project in the solution template. Are you unfolding a solution template as part of the recipe you are execiting, aren't you?
-Adrian
|
| Adrian Alonso Wednesday, August 15, 2007 2:25 PM |
Yes you are right, i'm unfolding solution template. Thanks for the reply, i'll try it and will write back if i was able to do it or not (or any other problem  ). Azeem Faraz. |
| Azeem Fraz Wednesday, August 15, 2007 2:33 PM |
Hi,
I'm not able to add project using AddFromTemplate method. Can you please give me an idean how can I get paths that i need to provide in the AddFromTemplate mothod? I'm trying with DteHelper.GetPathFull method. Just to let you know that i've my project under Templates\Solutions\Projects.
Please help.
Thanks.
Azeem Faraz
|
| Azeem Fraz Wednesday, August 15, 2007 8:21 PM |
Try to Combine the IConfigurationService's BasePath with your relative template location (Templates\Solutions\Projects\MyProject.vstemplate).
IConfigurationService confService = GetService(typeof(IConfigurationService)) as IConfigurationService; string templateFullPath = Path.Combine(confService.BasePath, "Templates\Solutions\Projects\MyProject.vstemplate");
-Adrian
|
| Adrian Alonso Wednesday, August 15, 2007 9:28 PM |
I tried with this but i got error "Value does not fall within the expected range". Other thing i noticed is that templateFullPath is pointing to the bin directory of the solution where i've developing this guidance package. Would it work if i use setup file to deploy this guidance package?
Azeem Faraz
|
| Azeem Fraz Wednesday, August 15, 2007 9:44 PM |
Sorry Adrian, it worked. It was my fault. I was having wrong path for template file.
Thanks.
|
| Azeem Fraz Wednesday, August 15, 2007 9:52 PM |
Glad it worked!
-Adrian
|
| Adrian Alonso Wednesday, August 15, 2007 10:01 PM |
I got an issue; when i add a project using AddFromTemplate method, its always returning null as project. But the project is being added in the solution. Why is it always returning null, any idea?
Thanks
Azeem Faraz.
|
| Azeem Fraz Thursday, August 16, 2007 12:00 AM |
It's probably the behavior of the implementation. I remeber I had a similar issue adding a Project Item. What I did is to search the Item after adding it. -Adrian
|
| Adrian Alonso Thursday, August 16, 2007 12:26 AM |
yeah i found an article saying same almost same
http://www.mztools.com/articles/2006/mz2006019.aspx
You said search the item, I tried but still couldn't find it. Its a web project this time. I tried using DteHelper.FindProjectByName and DteHelper.FindProjectByPath but it always returned null. I'm on to it but if you have any idea, let me know.
Thanks.
Azeem Faraz
|
| Azeem Fraz Thursday, August 16, 2007 1:38 PM |
It's probably something related to the Solution Folder where the project is. Once I used the ProjectByPathExpressionProvider value provider included in the WSSF V2 which it worked. I had to pass to it the project name including the Solution Folder name as part of the name.
HTH -Adrian
|
| Adrian Alonso Thursday, August 16, 2007 2:11 PM |
Thanks for replying. I used "Web Application Project" instead of VS2005 website. Web Application Project is provided to support the same structure as in VS2003.
http://msdn2.microsoft.com/en-us/asp.net/Aa336618.aspx
I can do what what i wanted to do with it.
Thanks.
Azeem Faraz
|
| Azeem Fraz Thursday, August 16, 2007 6:39 PM |
Hello,
Can you post your solution? I can't seem to follow how it was done. Thanks! |
| Keirol Thursday, September 20, 2007 11:14 AM |