My project creates a class library and a website. I am using the sample that installed itself and modifying it as needed. My samplesolution.vstemplate has the following entry to create my solution:
< ProjectTemplateLink ProjectName="APP_BL">Projects\ClassLibrary\ClassLibrary.vstemplate</ProjectTemplateLink>
< ProjectTemplateLink ProjectName="$WebSiteName$">Projects\WebSite\WebSite.vstemplate</ProjectTemplateLink>
There are certain dll's that I would like to reference in both the APP_BL library and the website that gets created. I also would like to reference APP_BL in the website as well.
I have been unsuccessful in trying to implement Microsoft.Practices.RecipeFramework.Library.Solution.Actions.AddReferenceAction in creating references.
Below is the error message I receive after calling a recipe from my website.vstemplatethat has an action of type Microsoft.Practices.RecipeFramework.Library.Solution.Actions.AddReferenceAction.
Any help in creating file and/or project references would be appreciated.
Thanks,
Kosmo
Output window created.
(*) Error: 0 : System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.Practices.RecipeFramework.VisualStudio.Library.Templates.T4UnfoldAction.IsTemplateFile(String filePath, String& content)
at Microsoft.Practices.RecipeFramework.VisualStudio.Library.Templates.T4UnfoldAction.ProcessFile(String filePath, ProjectItem prItem)
at Microsoft.Practices.RecipeFramework.VisualStudio.Library.Templates.T4UnfoldAction.ProcessProjectItem(ProjectItem prItem)
at Microsoft.Practices.RecipeFramework.VisualStudio.Library.Templates.T4UnfoldAction.Execute()
at Microsoft.Practices.RecipeFramework.VisualStudio.Templates.TemplateGatheringService.ProcessT4Templates()
(*) Error: 0 : Microsoft.Practices.RecipeFramework.ActionExecutionException: An exception occurred during the binding of reference or execution of recipe AddMyAssembly. Error was: Action AddReference failed to execute:
Unable to cast COM object of type 'System.__ComObject' to interface type 'VSLangProj.VSProject'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{2CFB826F-F6BF-480D-A546-95A0381CC411}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE))..
You can remove the reference to this recipe through the Guidance Package Manager. ---> System.InvalidCastException: Unable to cast COM object of type 'System.__ComObject' to interface type 'VSLangProj.VSProject'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{2CFB826F-F6BF-480D-A546-95A0381CC411}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
at Microsoft.Practices.RecipeFramework.Library.Solution.Actions.AddReferenceAction.Execute()
at Microsoft.Practices.RecipeFramework.Recipe.Microsoft.Practices.RecipeFramework.Services.IActionExecutionService.Execute(String actionName, Dictionary`2 inputValues)
at Microsoft.Practices.RecipeFramework.Recipe.Microsoft.Practices.RecipeFramework.Services.IActionExecutionService.Execute(String actionName)
at Microsoft.Practices.RecipeFramework.Recipe.Microsoft.Practices.RecipeFramework.Services.IActionCoordinationService.Run(Dictionary`2 declaredActions, XmlElement coordinationData)
at Microsoft.Practices.RecipeFramework.Recipe.ExecuteActions(IDictionaryService readOnlyArguments, IDictionaryService arguments, ITypeResolutionService resolution)
--- End of inner exception stack trace ---
at Microsoft.Practices.RecipeFramework.Recipe.UndoExecutedActionsAndRethrow(Exception ex)
at Microsoft.Practices.RecipeFramework.Recipe.ExecuteActions(IDictionaryService readOnlyArguments, IDictionaryService arguments, ITypeResolutionService resolution)
at Microsoft.Practices.RecipeFramework.Recipe.Execute(Boolean allowSuspend)
at Microsoft.Practices.RecipeFramework.GuidancePackage.Execute(String recipe, IAssetReference reference, IDictionary arguments)
at Microsoft.Practices.RecipeFramework.GuidancePackage.ExecuteFromTemplate(String recipe, IDictionary arguments)
at Microsoft.Practices.RecipeFramework.VisualStudio.Templates.UnfoldTemplate.ExecuteRecipe(Boolean executeActions)
at Microsoft.Practices.RecipeFramework.VisualStudio.Templates.UnfoldTemplate.RunFinished() | | Kosmo007 Wednesday, January 17, 2007 4:11 PM | Hi Kosmo,
I won't recommend at all storing shared fileson network shared. What I would do here is to check-in into SCC (as a way to share files and have real control over them, e.g: security, versioning, etc) and have these DLLs in a well-known location of your source tree. You could then reference them with a relative path if you wanted to. This is what we use in the Clarius Software Factories Toolkit, where we have a source tree similar to:
src | |---> MetaFactory |---> Lib
MetaFactory is a folder containing the MetaFactory.csproj project which has a file reference to some DLLs that are found in the Lib folder, so we use something similar to this:
<HintPath>..\Lib\Microsoft.VisualStudio.Shell.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL</HintPath>
Also adding a file reference to a project, should be really simple to do, if you're still having issues with that I could try to get you a very simple guidance package which does that so you can use it as a jumpstart.
HTH, -Victor. | | vga Friday, January 19, 2007 5:06 AM | Since I couldn't programmatically figure out how to add a file reference to a project I have found another way.
My class library has a .vbproj file that I am also including in the template.
Within the vbproj file I added the following lines:
< ItemGroup>
< Reference Include="MyDLL, Version=2.0.0.5, Culture=neutral, processorArchitecture=MSIL">
< SpecificVersion>False</SpecificVersion>
< HintPath>\\ServerLocation\Assembly\MyDLL.dll</HintPath>
</ Reference>
</ItemGroup>
For my website, I simply created a bin folder in the GAT template and added lines to the website.vstemplate as such:
< Folder Name="bin">
< ProjectItem>MyDLL.dll</ProjectItem>
</Folder>
This appears to work fine as I've been playingaround with it and haven't noticed any issues.
Is there any reason why I wouldn't want to do it this way? Is it possible in the website.vstemplate to have the file location be the \\ServerLocation\Assembly\MyDLL.dll also. This way, both projects are pulling the dll from the same location.
Thanks,
Kosmo
| | Kosmo007 Thursday, January 18, 2007 3:28 PM | Hi Kosmo,
I won't recommend at all storing shared fileson network shared. What I would do here is to check-in into SCC (as a way to share files and have real control over them, e.g: security, versioning, etc) and have these DLLs in a well-known location of your source tree. You could then reference them with a relative path if you wanted to. This is what we use in the Clarius Software Factories Toolkit, where we have a source tree similar to:
src | |---> MetaFactory |---> Lib
MetaFactory is a folder containing the MetaFactory.csproj project which has a file reference to some DLLs that are found in the Lib folder, so we use something similar to this:
<HintPath>..\Lib\Microsoft.VisualStudio.Shell.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL</HintPath>
Also adding a file reference to a project, should be really simple to do, if you're still having issues with that I could try to get you a very simple guidance package which does that so you can use it as a jumpstart.
HTH, -Victor. | | vga Friday, January 19, 2007 5:06 AM | Victor,
I am still having issues adding a file reference to a project as I've resorted to editing the vbproj for my Class library and adding them to a folder in the website.vstemplate as explained in a previous post. Also, I am still unable to create a reference to my class library in my website.
If you can provide a simple package with an example of either/both of these it would be greatly appreciated.
Below is the recipe that I was trying to use in order to add file references which I could not get to work:
< Recipe Name="AddMyAssembly">
< Caption>Collects information for the new solution.</Caption>
< Arguments>
< Argument Name="ReferenceNameArg">
< ValueProvider Type="Microsoft.Practices.RecipeFramework.Library.ValueProviders.ExpressionEvaluatorValueProvider,Microsoft.Practices.RecipeFramework.Library" Expression="c:\MyDLL.dll"/>
</ Argument>
< Argument Name="ProjectArg" Type="EnvDTE.Project, EnvDTE, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
< ValueProvider Type="Microsoft.Practices.RecipeFramework.Library.ValueProviders.FirstSelectedProject, Microsoft.Practices.RecipeFramework.Library" />
</ Argument>
</ Arguments>
< Actions>
< Action Name="AddReference" Type="Microsoft.Practices.RecipeFramework.Library.Solution.Actions.AddReferenceAction, Microsoft.Practices.RecipeFramework.Library">
< Input Name="ReferenceName" RecipeArgument="ReferenceNameArg"/>
< Input Name="ReferringProject" RecipeArgument="ProjectArg"/>
</ Action>
</ Actions>
</ Recipe>
Also, here is the portion of my solution template that creates the Class Library and website. Not sure if this might help.
< TemplateContent>
< ProjectCollection>
< ProjectTemplateLink ProjectName="APP_BL">Projects\ClassLibrary\ClassLibrary.vstemplate</ProjectTemplateLink>
< ProjectTemplateLink ProjectName="$WebSiteName$">Projects\WebSite\WebSite.vstemplate</ProjectTemplateLink>
</ ProjectCollection>
</ TemplateContent>
Kosmo
| | Kosmo007 Friday, January 19, 2007 3:46 PM | Victor,
I have tried to use the HoL as an example of creating a project reference but was unavailable to. I'm assuming its because I'm trying to add a reference to a class library within a website project.
Also, I am unable to add file references to either my class library or the website except for how I explained above which isn't a great way to do it.
I will provide my vstemplate files in hopes that it helps in providing an example of how I can achieve these functions.
Below is my Solution.vstemplate for GAT:
< VSTemplate Version="2.0" Type="ProjectGroup" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005"> <TemplateData> <Name>MyGuidanceTemplate Sample Solution</Name> <Description>MyGuidanceTemplate Sample Solution</Description> <ProjectType>VisualBasic</ProjectType> <SortOrder>90</SortOrder> <Icon>SampleSolution.ico</Icon> <CreateNewFolder>false</CreateNewFolder> <DefaultName>MyGuidanceTemplateSolution</DefaultName> <ProvideDefaultName>true</ProvideDefaultName> </TemplateData> <TemplateContent> <ProjectCollection> <ProjectTemplateLink ProjectName="APP_BL">Projects\ClassLibrary\ClassLibrary.vstemplate</ProjectTemplateLink> <ProjectTemplateLink ProjectName="$WebSiteName$">Projects\WebSite\WebSite.vstemplate</ProjectTemplateLink> </ProjectCollection> </TemplateContent> <WizardExtension> <Assembly>Microsoft.Practices.RecipeFramework.VisualStudio, Version=1.0.60429.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</Assembly> <FullClassName>Microsoft.Practices.RecipeFramework.VisualStudio.Templates.UnfoldTemplate</FullClassName> </WizardExtension> <WizardData> <Template xmlns="http://schemas.microsoft.com/pag/gax-template" SchemaVersion="1.0" Recipe="CreateSolution"> </Template> </WizardData> </VSTemplate>
My ClassLibrary.vstemplate:
< VSTemplate Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" Type="Project"> <TemplateData> <Name>BusinessLogic</Name> <Description><No description available></Description> <Icon Package="{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}" ID="4547" /> <ProjectType>VisualBasic</ProjectType> <SortOrder>1000</SortOrder> <CreateNewFolder>true</CreateNewFolder> <DefaultName>APP_BL</DefaultName> <ProvideDefaultName>true</ProvideDefaultName> <LocationField>Enabled</LocationField> <EnableLocationBrowseButton>true</EnableLocationBrowseButton> </TemplateData> <TemplateContent> <Project File="App_BL.vbproj" ReplaceParameters="true"> <ProjectItem ReplaceParameters="true">Properties\AssemblyInfo.vb</ProjectItem> <ProjectItem ReplaceParameters="true">Class1.vb</ProjectItem>| </Project> </TemplateContent> <WizardExtension> <Assembly>Microsoft.Practices.RecipeFramework.VisualStudio, Version=1.0.60429.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</Assembly> <FullClassName>Microsoft.Practices.RecipeFramework.VisualStudio.Templates.UnfoldTemplate</FullClassName> </WizardExtension> </VSTemplate>
My website.vstemplate: (The bin folder is how I am currently adding file references to my website.)
< VSTemplate Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" Type="Project"> <TemplateData> <Name>WebSite</Name> <Description><No description available></Description> <Icon Package="{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}" ID="4547" /> <ProjectType>Web</ProjectType> <ProjectSubType>VisualBasic</ProjectSubType> <SortOrder>1000</SortOrder> <CreateNewFolder>true</CreateNewFolder> <DefaultName>WService</DefaultName> <ProvideDefaultName>true</ProvideDefaultName> <LocationField>Enabled</LocationField> <EnableLocationBrowseButton>true</EnableLocationBrowseButton> </TemplateData> <TemplateContent> <Project TargetFileName="WebSite.webproj" File="WebSite.webproj" ReplaceParameters="true"> <Folder Name="bin"> <ProjectItem>MyAssembly.dll</ProjectItem> </Folder> <ProjectItem>Default.aspx</ProjectItem> <ProjectItem>Default.aspx.vb</ProjectItem> </Folder> <ProjectItem>Default.aspx</ProjectItem> <ProjectItem>Default.aspx.vb</ProjectItem> <ProjectItem>MyMaster.master</ProjectItem> <ProjectItem>MyMaster.master.vb</ProjectItem> <ProjectItem>Web.config</ProjectItem> </Project> </TemplateContent> <WizardExtension> <Assembly>Microsoft.Practices.RecipeFramework.VisualStudio, Version=1.0.60429.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</Assembly> <FullClassName>Microsoft.Practices.RecipeFramework.VisualStudio.Templates.UnfoldTemplate</FullClassName> </WizardExtension> </VSTemplate>
Kosmo | | Kosmo007 Friday, January 26, 2007 7:24 PM | Problem partially solved...
I can programmatically add file references only to my class library now, but not the website. I still can't add my class library as a reference to my website.
Here's what I did...
I created an AddProjRef.cs and added it to my Actions folder. In it I loop through the solutions projects. Based on the name of the project I know if its the class library or not as that is hardcoded in my solution.vstemplate. From there I send it to one of two functions. The website portion of it iscommented out as that is causing it to error out.
In the CreateSolution recipe, I appended the following:
< Actions>
< Action Name="AddProjRef" Type="Test.Guidance.Actions.AddProjRef, TestGuidanceTemplate">
</ Action>
</ Actions>
My AddProjRef.cs file looks like:
namespace Test.Guidance.Actions
{
public class AddProjRef : Action
{
#region IAction Members
public override void Execute()
{
EnvDTE. DTE dte = (EnvDTE.DTE)GetService(typeof(EnvDTE.DTE));
Project project = null;
VsWebSite. VSWebSite site = null;
Project referenceProject = null;
foreach(Project proj in dte.Solution.Projects)
{
if (proj != null)
{
if (proj.Name.Equals("APP_BL"))
{
project = proj;
}
// THIS ISN'T WORKING
//else
//{
// site = (VsWebSite.VSWebSite)proj;
// //AddWebsiteReference((VsWebSite.VSWebSite)proj);
//}
}
}
if (!AddProjectReference(project))
{
}
// THIS ISN'T WORKING
//if (!AddWebsiteReference(site))
//{
//}
}
public override void Undo()
{
}
#endregion
#region Private Methods
private bool AddProjectReference(Project aProject)//, Project aReferenceProject)
{
//if (aProject == null || aReferenceProject == null)
// return false;
VSLangProj. VSProject aVSProject = (VSLangProj.VSProject)aProject.Object;
aVSProject.References.Add( "C:\\MyAssembly.dll");
//.AddProject(aReferenceProject);
return true;
}
private bool AddWebsiteReference(VsWebSite.VSWebSite site)
{
site.References.AddFromFile( "C:\\MyAssembly.dll");
return true;
}
#endregion
}
}
Will keep plugging away at this.
Kosmo
| | Kosmo007 Friday, January 26, 2007 9:54 PM | I was able to get the website references to work by changing a few lines from the previous post.
Changed VsWebSite.VSWebSite site = null; to Project site = null;
Then if the project name was not App_BL then I performed the following:
VsWebSite. VSWebSite aVSProject = (VsWebSite.VSWebSite)site.Object;
aVSProject.References.AddFromFile("C:\\MyAssembly.dll");
Also by changing the parameters to AddWebsiteReference to have it take both the website and project, I could add the project as a reference to the website as:
aVSWebsite.References.AddFromProject(proj);
Now I'm not sure if there is an easier way to do all this but it works for me.
I'd be happy to share the code if anyone has any questions about it.
Kosmo | | Kosmo007 Monday, January 29, 2007 2:13 PM | Hi Kosmo007,
Ialso encountered the same predicament on a custom guidance package my team was working on. I'm still in the process of figuring it out on my part but would appreciate if you can share a copy of the code. This will surely tie up the loose ends.
Newbie, ferdz | | ferdz Wednesday, January 30, 2008 3:55 PM |
|