Hello,
I'm wondering if it is possible to rename a file that is embedded in a project
template, after the template has been instanitated by creating a new project
from it.
The technique I have been attempting is to use an IWizard for the project
to change the name of TargetFileName attribute in my VSTemplate file, using
the replacements dictionary in the RunStarted() method.
e.g.: <ProjectItem ReplaceParameters="true" TargetFileName="$suggestedmodel$.cw">Workflow1.cw</ProjectItem>
This does not appear to be working and I'm hoping someone has had experience
using IWizard and can suggest an appropriate solution.
I'm getting the following error:
Unable to copy the file 'Workflow1.cw' from the project template to the project.
Cannot find the file 'C:\Documents and Settings\Temp\obbjix.dae\Temp\Workflow1.cw'.
The only other thing to try that I can think of is to put code in the ProjectItemFinishedGenerating(),
look for 'Workflow1.cw' ProjectItem, and attempt to rename the file there.
I'm trying to follow the documentation from:
http://msdn2.microsoft.com/en-us/library/ms185301(VS.80).aspx
Here is my vstemplate file:
<VSTemplate Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005"
Type="Project">
<TemplateData>
<Name Package="{c7232e0a-b11d-4ceb-ae93-3a7760f598af}" ID="4000" />
<Description Package="{c7232e0a-b11d-4ceb-ae93-3a7760f598af}" ID="4001"
/>
<Icon Package="{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}" ID="4547" />
<ProjectType>CSharp</ProjectType>
<ProjectSubType>
</ProjectSubType>
<SortOrder>1</SortOrder>
<CreateNewFolder>true</CreateNewFolder>
<DefaultName>CaptarisWorkflow</DefaultName>
<ProvideDefaultName>true</ProvideDefaultName>
<LocationField>Enabled</LocationField>
<EnableLocationBrowseButton>true</EnableLocationBrowseButton>
<NumberOfParentCategoriesToRollUp>1</NumberOfParentCategoriesToRollUp>
</TemplateData>
<TemplateContent>
<Project TargetFileName="Captaris Workflow.csproj" File="Captaris Workflow.csproj"
ReplaceParameters="true">
<Folder Name="Properties" TargetFolderName="Properties">
<ProjectItem ReplaceParameters="true" TargetFileName="AssemblyInfo.cs">AssemblyInfo.cs</ProjectItem>
</Folder>
<ProjectItem ReplaceParameters="true" TargetFileName="$suggestedmodel$.cw">Workflow1.cw</ProjectItem>
</Project>
</TemplateContent>
<WizardExtension>
<Assembly>Captaris.Workflow.Designer.VisualStudio.PackageWizard, Version=6.0.0.0,
Culture=Neutral, PublicKeyToken=62115509e7409ce3</Assembly>
<FullClassName>Captaris.Workflow.Designer.VisualStudio.PackageWizard.ModelWizard</FullClassName>
</WizardExtension>
</VSTemplate>
Here is my wizard code:
//-----------------------------------------------------------------------------
// CODE CHANGE HISTORY
//-----------------------------------------------------------------------------
// Date Developer Description
// ------------ --------------- -----------------------------------------------
// 2005-Apr-06 DarenYong Created.
//-----------------------------------------------------------------------------
using EnvDTE;
using Microsoft.VisualStudio.TemplateWizard;
using System.Collections.Generic;
namespace Captaris.Workflow.Designer.VisualStudio.PackageWizard
{
public class ModelWizard : IWizard
{
#region IWizard
public void RunStarted(object automationObject, Dictionary<string,
string> replacementsDictionary, WizardRunKind runKind, object[] customParams)
{
if (runKind == WizardRunKind.AsNewItem)
{
}
else if (runKind == WizardRunKind.AsNewProject
|| runKind == WizardRunKind.AsMultiProject)
{
string suggestedModelName
= "foobar";
replacementsDictionary.Add("$suggestedmodel$",
suggestedModelName);
}
}
public void ProjectFinishedGenerating(Project project)
{
}
public void ProjectItemFinishedGenerating(ProjectItem
projectItem)
{
}
public bool ShouldAddProjectItem(string filePath)
{
return true;
}
public void BeforeOpeningFile(ProjectItem projectItem)
{
}
public void RunFinished()
{
}
#endregion IWizard
} // end class
} // end namespace
Best regards,
D.
David A. Kingston - 01 May 2006 02:15 GMT
According to this post on MS forums, there's a step missing in the
documentation:
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=137800&SiteID=1
You also need to edit the appropriate "Compile" node in the .csproj
file.
In your case, you need to change <Compile Include="Workflow1.cw"> to
<Compile Include="$suggestedmodel$.cw"> and it should work fine.
Marc Dambiermont - 30 Jun 2006 09:14 GMT
Hi,
Thanks for this help... but it's not perfect ;-((
It's ok for the ProjectItem Tag... but there is a problem with Project Tag ??
e.g.: <Project TargetFileName="AN$applicationcode$Controller_V20.vbproj"
File="ANaaController_V20.vbproj" ReplaceParameters="true" >
Here is my vstemplate file:
<VSTemplate Version="2.0.0"
xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" Type="Project">
<TemplateData>
<Name>ANaaController_V20</Name>
<Description>Description Controller</Description>
<ProjectType>VisualBasic</ProjectType>
<ProjectSubType></ProjectSubType>
<SortOrder>1000</SortOrder>
<CreateNewFolder>false</CreateNewFolder>
<DefaultName>ANaaController_V20</DefaultName>
<ProvideDefaultName>true</ProvideDefaultName>
<LocationField>Hidden</LocationField>
<EnableLocationBrowseButton>false</EnableLocationBrowseButton>
<PromptForSaveOnCreation>false</PromptForSaveOnCreation>
<Icon>__TemplateIcon.ico</Icon>
</TemplateData>
<TemplateContent>
<Project TargetFileName="AN$applicationcode$Controller_V20.vbproj"
File="ANaaController_V20.vbproj" ReplaceParameters="true" >
<ProjectItem ReplaceParameters="true"
TargetFileName="KN$applicationcode$Controller_V20.vb">KNaaController_V20.vb</ProjectItem>
<ProjectItem ReplaceParameters="true"
TargetFileName="KN$applicationcode$FControllerException_V20.vb">KNaaFControllerException_V20.vb</ProjectItem>
<Folder Name="My Project" TargetFolderName="My Project">
<ProjectItem ReplaceParameters="true"
TargetFileName="Application.myapp">Application.myapp</ProjectItem>
<ProjectItem ReplaceParameters="true"
TargetFileName="Application.Designer.vb">Application.Designer.vb</ProjectItem>
<ProjectItem ReplaceParameters="true"
TargetFileName="AssemblyInfo.vb">AssemblyInfo.vb</ProjectItem>
<ProjectItem ReplaceParameters="true"
TargetFileName="Resources.resx">Resources.resx</ProjectItem>
<ProjectItem ReplaceParameters="true"
TargetFileName="Resources.Designer.vb">Resources.Designer.vb</ProjectItem>
<ProjectItem ReplaceParameters="true"
TargetFileName="Settings.settings">Settings.settings</ProjectItem>
<ProjectItem ReplaceParameters="true"
TargetFileName="Settings.Designer.vb">Settings.Designer.vb</ProjectItem>
</Folder>
</Project>
</TemplateContent>
<WizardExtension>
<Assembly>ANXVWizardAssemblies_V20, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=96055bda31e65133</Assembly>
<FullClassName>Fortis.FIBE.XV.AddIn.WizardAssemblies</FullClassName>
</WizardExtension>
</VSTemplate>
> According to this post on MS forums, there's a step missing in the
> documentation:
[quoted text clipped - 5 lines]
> In your case, you need to change <Compile Include="Workflow1.cw"> to
> <Compile Include="$suggestedmodel$.cw"> and it should work fine.