I have a project template that contains a powershell script called BuildStandard.ps1. Inside that script is the following excerpt:
Invoke-psake -buildFile $psakeScript `
-parameters #{
"solutionFile" = Resolve-Path("..\$SpecificSolutionName$.sln")
}
When a new project is added using the template, I want the $SpecificSolutionName$ parameter to be replaced with, well, the solution name. Only problem is that this content from the .vstemplate file isn't cutting it:
<TemplateContent>
<Project TargetFileName="PsakeInstallTestBench.csproj" File="PsakeInstallTestBench.csproj" ReplaceParameters="true">
<ProjectItem ReplaceParameters="true">BuildStandard.ps1</ProjectItem>
</Project>
</TemplateContent>
What am I missing?
EDIT:
I've verified that if I replace $SpecificSolutionName$ with $safeprojectname$, the parameter is replaced. I'm beginning to wonder if $SpecificSolutionName$ is available only for solution-level templates. Is there a workaround for this?
Related
I am having trouble getting Visual Studio project templates to work correctly.
I have edited the .vstemplate file in order to allow VS to rename project files when a new project is created from the template.
Some of the files are not copied or renamed when the new project is created.
I have a C++ project named Minimal that I have exported as a template.
I am currently NOT using any replaceable parameters in the Minimal template project.
The Minimal.zip folder in the Project Templates directory contains:
__TemplateIcon.ico (created by VS when the project was exported)
Minimal.cpp (my code)
Minmal.rc (a resource file containing a string table with one entry)
Minimal.vcxproj (created by VS at project creation time),
Minimal.vcxproj.filters (created by VS at project creation time)
MyTemplate.vstemplate (an XML file created by VS when the project was exported)
resource.h (created by VS at project creation time).
The MyTemplate.vstemplate file looks like this after editing:
<VSTemplate Version="3.0.0" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" Type="Project">
<TemplateData>
<Name>Minimal</Name>
<Description><No description available></Description>
<ProjectType>VC</ProjectType>
<ProjectSubType>
</ProjectSubType>
<SortOrder>1000</SortOrder>
<CreateNewFolder>true</CreateNewFolder>
<DefaultName>Minimal</DefaultName>
<ProvideDefaultName>true</ProvideDefaultName>
<LocationField>Enabled</LocationField>
<EnableLocationBrowseButton>true</EnableLocationBrowseButton>
<Icon>__TemplateIcon.ico</Icon>
</TemplateData>
<TemplateContent>
<Project TargetFileName="Minimal.vcxproj" File="Minimal.vcxproj" ReplaceParameters="true">
<ProjectItem ReplaceParameters="false" TargetFileName="$projectname$.vcxproj.filters">Minimal.vcxproj.filters</ProjectItem>
<ProjectItem ReplaceParameters="false" TargetFileName="$projectname$.cpp">Minimal.cpp</ProjectItem>
<ProjectItem ReplaceParameters="false" TargetFileName="resource.h">resource.h</ProjectItem>
<ProjectItem ReplaceParameters="true" TargetFileName="$projectname$.rc">Minimal.rc</ProjectItem>
</Project>
</TemplateContent>
</VSTemplate>
I edited the ProjectItem entries to use the $projectname$ parameters.
Two ProjectItems have ReplaceParameters set to "false" and a TargetFileName set to $projectname$.
One ProjectItem has ReplaceParameters set to "false" and TargetFileName unedited.
One ProjectItem has ReplaceParameters set to "true" and TargetFileName set to $projectname$.
I have a project named Test that I created from the Minimal template.
I would expect the Test project folder to contain one file for each ProjectItem, and the files that use the $projectname$ parameter to be renamed as Test.something.
The Test project folder actually contains this:
Test.sln (created by VS)
resource.h (not renamed, as expected)
Test.vcxproj (renamed, as expected)
Test.vcxproj.filters (renamed, as expected)
Test.vcxoproj.user (created by VS).
The Test project folder does not contain any .cpp or .rc file.
I have also tried not using $projectname$ for the .cpp file and the .rc file, and just used their original names, and they get copied into the new project.
Does anyone know what I need to do to make it work correctly with renamed files?
Trying to create my first Project Template for a simple VS2015 C# project. But when I try to create a Project with it, one of the files - post_build.bat - is missing.
The content of the project template ZIP file is:
AssemblyInfo.cs
Class1.cs
ImsProject.ico
ImsProject.vstemplate
post_build.bat
ProjectTemplate.csproj
The ImsProject.vstemplate file contains the following TemplateContent:
<TemplateContent>
<Project File="ProjectTemplate.csproj" ReplaceParameters="true">
<ProjectItem ReplaceParameters="true" TargetFileName="Properties\AssemblyInfo.cs">AssemblyInfo.cs</ProjectItem>
<ProjectItem ReplaceParameters="true" OpenInEditor="true">Class1.cs</ProjectItem>
<ProjectItem>post_build.bat</ProjectItem>
</Project>
</TemplateContent>
Seems simple, but I must be doing something wrong.
Stoopid me!
I was thinking the post_build.bat file was not present was because when I created a new project it did not appear in the Solution Explorer in Visual Studio.
However ... it was present in the folder containing the new project.
The problem was I hadn't created a entry in an ItemGroup in the ProjectTemplate.csproj file.
Adding
<ItemGroup>
<None Include="post_build.bat" />
</ItemGroup>
solved the problem
I am creating multiproject template for Visual studio using VSTemplate.
I am new to project template and refering this url to create multi project template for Visual Studio.
<VSTemplate Version="2.0.0" Type="ProjectGroup"
xmlns="http://schemas.microsoft.com/developer/vstemplate/2005">
<TemplateData>
<Name>MVC with Repo and UoW</Name>
<Description>Basic by Jenish</Description>
<Icon>Icon.ico</Icon>
<ProjectType>CSharp</ProjectType>
<ProjectSubType>
</ProjectSubType>
<SortOrder>1000</SortOrder>
<CreateNewFolder>false</CreateNewFolder>
<DefaultName>MVC</DefaultName>
<ProvideDefaultName>true</ProvideDefaultName>
<LocationField>Enabled</LocationField>
<EnableLocationBrowseButton>true</EnableLocationBrowseButton>
</TemplateData>
<TemplateContent>
<ProjectCollection>
<ProjectTemplateLink ProjectName="$safeprojectname$.Common">
KLS.Common\MyTemplate.vstemplate
</ProjectTemplateLink>
<ProjectTemplateLink ProjectName="$safeprojectname$.Data.Contract">
KLS.Data.Contract\MyTemplate.vstemplate
</ProjectTemplateLink>
<ProjectTemplateLink ProjectName="$safeprojectname$.Data.Repositories">
KLS.Data.Repositories\MyTemplate.vstemplate
</ProjectTemplateLink>
<ProjectTemplateLink ProjectName="$safeprojectname$.Manager">
KLS.Manager\MyTemplate.vstemplate
</ProjectTemplateLink>
<ProjectTemplateLink ProjectName="$safeprojectname$.Models">
KLS.Models\MyTemplate.vstemplate
</ProjectTemplateLink>
<ProjectTemplateLink ProjectName="$safeprojectname$.Web">
KLSFoods\MyTemplate.vstemplate
</ProjectTemplateLink>
</ProjectCollection>
</TemplateContent>
<WizardExtension>
<Assembly>RestTemplateWizard, Version=1.0.0.0, Culture=neutral, PublicKeyToken=c9a76f51a8a9555f</Assembly>
<FullClassName>RestTemplateWizard.RootWizard</FullClassName>
</WizardExtension>
</VSTemplate>
screenshot 1:
As per above screen shot Mytemplate.vstemplate is main root file and all the folder except packages contains separate vstemplate file for each project.
Now problem is I want same structure to be generated as it appears on the first screen shot but it generates solution in outer directory. Is there any way I can force the template to create solution as per screen shot1.
Template is currently generating the solution like this.
screenshot 2:
Mvc1 will hold all the project folder and what I want is create solution file where all the project folder is defined. because currently it refers the packages folder wrongly
Thanks in advance.
3 years late, but this may help others.
1) In your wizard class declare a DTE field, and save the automationObject parameter to RunStarted(...) in this field:
public class MyWizard : IWizard
{
DTE dte;
...
public void RunStarted( object automationObject, Dictionary<string, string> replacementsDictionary, WizardRunKind runKind, object[] customParams )
{
dte = automationObject as DTE;
...
2) In RunFinished, use the dte object to save the solution wherever you want:
public void RunFinished()
{
if( dte != null )
{
var solution = dte.Solution;
var path = <whatever path you want>;
solution.SaveAs( path );
}
...
You may want to inspect the contents of replacementsDictionary at RunStarted and use one of the values in there; for instance, you can use the $destinationdirectory$ entry to construct the path to the solution file (I'm using that one).
I had the same issue, my workaround was to edit the solution file (*.sln) and move the file in the expected folder.
This is the folder structure generated by the template (not what I was expecting):
My Solution folder:
notice the .sln file not in the same folder of the projects
folder DDD_Backend10xxxx, contains all the projects:
step 1: Move the .sln file in the sub folder containing all the projects (as required for project to work):
*.sln file moved to same folder with the rest of the projects
The .sln file is now with the project folders and in the correct solution folder level.
step 2: open and edit the .sln file and modify the paths of ALL the projects:
Paths not edited that cause ERRORS:
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "BusinessLayer", "DDD_Backend10xxxx\BusinessLayer", "{F9E1B70C-F692-414B-97C6-BCEC22F6C1F3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BusinessLayer", "DDD_Backend10xxxx\BusinessLayer\BusinessLayer.csproj", "{0CF94CF4-97C6-4079-8F60-672CBE9B77D5}"
EndProject
//Other project references...
Fixed edited paths: remove the folder "DDD_Backend10xxxx" from path
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "BusinessLayer", "BusinessLayer", "{F9E1B70C-F692-414B-97C6-BCEC22F6C1F3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BusinessLayer", "BusinessLayer\BusinessLayer.csproj", "{0CF94CF4-97C6-4079-8F60-672CBE9B77D5}"
EndProject
//Other project references...
step 3: modify the primary/root project root_project_name.csproj file, for nuget extension reference path.
Modify any reference to the packages folder, so that they'll reference the packages folder in the same folder level.
ie.
from: Import Project="....\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1
to:
Import Project="..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1
This is an essential reference for nuget package update or installation.
step 4: Run nuget to update/restore the packages.
Once nuget updates/restores the packages a "packages" folder will be created in the correct folder level.
(Run the command update-package -reinstall in the Package Manager Console window.)
Instead of moving the .sln file and then editing it, just do a "Save as..." for the solution and put it in the same directory as the projects. Then you can then delete the original .sln file. Visual Studio will adjust all of the paths in the new .sln file to match where you are placing it.
That looks correct to me. And if you look at the documentation in the URL you provided it sounds like this is working correctly.
The solution should sit in the same directory as the project folders. If you look at screenshot1, that seems to be what is happening. It looks like in your example you're only creating a single project called MVC1 which is the only project in a solution called MVC1. The code snippet you've provided also doesn't match up with screenshot2. You may also want to include the template file you're actually using to generate the solution as well.
I have a .cs file with a base class that I want to use from within many projects. I've first placed this cs file above the project folder (along side the .sln). Then, within the project, I've changed the
<Compile Include="BaseClass.cs">
to
<Compile Include="..\BaseClass.cs">
This works, and the file icon then has a little shortcut arrow.
The problem comes when I want to export the project as a project template. The BaseClass does not get included in the template because it is outside the project folder. I've tried adding the BaseClass.cs to the template zip and adding
<ProjectItem ReplaceParameters="true" TargetFileName="..\BaseClass.cs">BaseClass.cs</ProjectItem>
to the MyTemplate.vstemplate, but I get the error:
A target file name within the VSTemplate file is invalid, it contains a fully qualified path
If I remove the ..\, it includes the file directly.
If I leave the <ProjectItem> out of the .vstemplate file, and just put <Compile Include="..\BaseClass.cs"> in the .csproj file in the template, it looks for the file in Users/me/AppData/Local....
How can I get the template to reference a file outside the project directory?
This is a known issue which has not been solved by Microsoft : https://connect.microsoft.com/VisualStudio/feedback/details/565068/project-template-relative-file-path-does-not-work
You should be doing the mapping of the folders in the VSTemplate and not in the project. The VS would not do any manipulation but in the template.
An example would be something like this. The below would copy the file from the "InnerFolder" to the root.
<Folder Name="InnerFolder" TargetFolderName="." >
<ProjectItem ReplaceParameters="true" TargetFileName="Web.config">Web.config</ProjectItem>
</Folder>
Given demo solution with two VSX-projects:
1. Add New Project -> Extensibility -> Item Template - "ItemTemplate1"
2. Add New Project -> Extensibility -> VSIX Project - "VSIXProject1"
I did no changes in "ItemTemplate1", so it constains default item template (ItemTemplate1.vstemplate):
<VSTemplate Version="3.0.0" Type="Item" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005">
<TemplateData>
<Name>ItemTemplate1</Name>
<Description><No description available></Description>
<Icon>ItemTemplate1.ico</Icon>
<TemplateID>e298765c-97b8-4f4c-9b7b-a6b368f914df</TemplateID>
<ProjectType>CSharp</ProjectType>
<RequiredFrameworkVersion>2.0</RequiredFrameworkVersion>
<NumberOfParentCategoriesToRollUp>1</NumberOfParentCategoriesToRollUp>
<DefaultName>Class.cs</DefaultName>
</TemplateData>
<TemplateContent>
<References>
<Reference>
<Assembly>System</Assembly>
</Reference>
</References>
<ProjectItem ReplaceParameters="true">Class.cs</ProjectItem>
</TemplateContent>
</VSTemplate>
In VSIXProject1 I only edited source.extension.vsixmanifest adding reference to ItemTemplates1 project. After this vsixmanifest contains only one content description:
<Content>
<ItemTemplate>ItemTemplates</ItemTemplate>
</Content>
Then built it. In bin/debug I got VSIXProject1.vsix inside which I can see my item template in ItemTemplates\CSharp\1033\ItemTemplate1.zip file.
Everything looks great!
Except the fact it doesn't work. I run VSIXProject1.vsix, vsix installed (I can see it in the extension manager) but no any templates was copied to
"C:\Users\{UserName}\Documents\Visual Studio 2010\Templates\ItemTemplates" !
Templates that are installed through a VSIX don't get installed to the Templates folder in the user Documents folder. They get installed under %LocalAppData%\Microsoft\VisualStudio\10.0\Extensions\<YourExtensionFolder> with all the other content for that extension. (A VSIX install is basically just unzipping the VSIX to a folder.)
You should still be able to see the template when you try to add a new item to a C# project.
please check the website below.It has help to solve my issue.
http://silverlightdude.wordpress.com/2010/06/07/installing-the-prism-template-pack-for-visual-studio-2010/#comment-4