VS template parameters: Get partial project name - visual-studio-2017

I have a multi-project solution template.
I've created it using this guide.
My solution is generating multi-platform projects with a central shared project:
MyProject.Shared
MyProject.UWP
MyProject.Droid
etc.
The problem is that when I use $safeprojectname$.Shared in the csproj file of the individual projects (let's say in the UWP one) in order to add a reference to the shared project, what gets generated is MyProject1.UWP.Shared instead of MyProject1.Shared.
How do I refer to the shared project name / solution name from the individual projects?
P.S. There is the $SpecificSolutionName$ parameter, but that only works if the user checked the Create solution directory option, not good enough for me.
TL;DR
How do I get partial project name from parameter?

$ext_safeprojectname$ does the trick.
(credit)

In the root .vstemplate file you should use ProjectName="$projectname$" in ProjectTemplateLink tag:
<TemplateContent>
<ProjectCollection>
<ProjectTemplateLink ProjectName="$projectname$.Shared" CopyParameters="true">
MyProject.Shared\MyTemplate.vstemplate
</ProjectTemplateLink>
<ProjectTemplateLink ProjectName="$projectname$.UWP" CopyParameters="true">
MyProject.UWP\MyTemplate.vstemplate
</ProjectTemplateLink>
<ProjectTemplateLink ProjectName="$projectname$.Droid" CopyParameters="true">
MyProject.Droid\MyTemplate.vstemplate
</ProjectTemplateLink>
</ProjectCollection>
</TemplateContent>

Related

in smarty version3 I see in folder structure we have 2 plugin directory which should use for create custom plugin function?

see file structure in screenshot atachment
Hello Friends,
I see in smarty template version3 two plugin directory.
one into project folder and other into libs.
In libs folder we have plugins and sysplugins directory.
My question is I need to create a custom function so I need to put new
file into which
directory is best way?
Both way working I checked but which is the best way to put custom plugin file in which directory?
You can put plugins in any directory that has been added to the Smarty plugins_dir, but looking at your screenshot, it appears that the "other" plugins directory you are looking at is part of the demo application included in the Smarty distribution. You should just remove the demo directory entirely and put your plugins in the smarty/libs/plugins directory.

Using AsConfigured and still be able to get UnitTest results in TFS

So I am running into an issue when I go to build my projects using tfs build controller using the Output location "AsConfigred" it will not detect my unit tests. Let me give a little info on my setup.
TFS 2013 Update 2, Default Process Template
Here is a few screenshots that can hopefully help fill in what I can't in typing. I am copying my build out to a file share on our network so that we can use other utilities use the output. I don't want to use "PerProject" or "SingleFolder" because they mess up the file structure we have configured (These both will run the tests). So i have the files copy to folder names "SingleOutputFolder" which is a child of the DropLocation. I would like to be able to run from the drop folder or run from the bin folder for each of my tests (I don't care which). However it doesn't seem to detect/run ANY of the tests. Any help would be greatly appreciated. Please let me know if you need any additional information.
I have tried using ***test*.dll, Install\SingleFolderOutput**.test.dll, and $(TF_BUILD_DROPLOCATION)\Install\SingleFolderOutput*test*.dll
But I am not sure what variables are available and understand where the scope of its execution is.
Given that you're using Build Output location set to AsConfigured you have to change the default values of the Test sources spec setting to allow build to find the test libraries in the bin folders. Here's an example.
If the full path to the unit test libraries is:
E:\Builds\7\<TFS Team Project>\<Build Definition>\src\<Unit Test Project>\bin\Release\*test*.dll
use
..\src\*UnitTest*\bin\*\*test*.dll;
This question was asked on MSDN forums here.
MSDN Forums Suggested Workaround
The suggested workaround in the accepted answer (as of 8 a.m. on June 20) is to specify the full path to the test projects' binary folders: For example:
C:\Builds\{agentId}\{teamProjectName}\{buildDefinitionName}\src\{solutionName}\{testProjectName}\bin*\Debug\*test*.dll*
which really should have been shown as
{agentWorkingFolder}\src\{relativePathToTestProjectBinariesFolder}\*test*.dll
However this approach is very brittle, for the following reasons:
Any new test projects you add to the solution will not be executed until you add them to the build definition's list of test sources:
It will break under any of the following circumstances:
the build definition is renamed
the working folder in build agent properties is modified
you have multiple build agents, and a different agent than the one you specified in {id} runs the build
Improved Workaround
My workaround mitigates the issues listed in #2 (can't do anything about #1).
In the path specified above, replace the initial part:
{agentWorkingFolder}
with
..
so you have
..\src\{relativePathToTestProjectBinariesFolder}\*test*.dll
This works because the internal working directory is apparently the \binaries\ folder that is a sibling of the \src\ folder. Navigating up to the parent folder (whatever it is named, we don't care) and back in to \src\ before specifying the path to the test projects binaries does the trick.
Note: If you have multiple test projects, you add additional entries, separated with semicolons:
..\src\{relativePathToTestProjectONEBinariesFolder}\*test*.dll;..\src\{relativePathToTestProjectTWOBinariesFolder}\*test*.dll;..\src\{relativePathToTestProjectTHREEBinariesFolder}\*test*.dll;
What I ended up doing was adding a post build event to copy all of the test.dll into the staging location folder in the specific build that is basically equivalent to where it would go on a SingleFolder build and do that on each test project.
if "$(TeamBuildOutDir)" == "" (
echo "Building Interactively not in TFS"
) else (
echo "Building in TFS"
xcopy "$(TargetDir)*.*" "$(TeamBuildBinaries)\" /Y /E /S
)
MSBUILD parameter in the build def that told it to basically drop in the folder that TFS looks for them.
/p:TeamBuildBinaries="$(TF_BUILD_BINARIESDIRECTORY)"
Kept the default Test assembly file specification:
**\*test*.dll
View this link for the information on the variable that I used and what relative path it exists at.
Another solution is to do the reverse.
Leave all of the files in the root so that all of the built in functionality works. There is more than just test execution in there. What about static code analysis, impact analysis..among others. You would have to do something custom for them all.
Instead use a pre-drop powershell script to create your Install arrangement from the root files.
If it is an application then you can use the _ApplicationFolder Nuget package to create an _PublishApplications folder same as you get for web applications.

SolutionFolder name change based on the project name in multiproject template

My multiproject vstemplate looks as below
<TemplateContent>
<ProjectCollection>
<SolutionFolder Name="samplefolder">
<ProjectTemplateLink ProjectName="$safeprojectname$.projectone">
sample.projectone\MyTemplate.vstemplate
</ProjectTemplateLink>
<ProjectTemplateLink ProjectName="$safeprojectname$.projecttwo">
sample.projecttwo\MyTemplate.vstemplate
</ProjectTemplateLink>
<ProjectTemplateLink ProjectName="$safeprojectname$.projectthree">
sample.projectthree\MyTemplate.vstemplate
</ProjectTemplateLink>
</SolutionFolder>
</ProjectCollection>
</TemplateContent>
Problem is I need to have the solutonfolder name to be same as the the projectname entered by user.
If I give $safeprojectname$' in the place of "samplefolder" the solution folder name is not being replaced.
Got the solution based on this post
How to change containing folder name for a project in VS 2010 template
by handling it in wizard.
Created solution folder, removed the projects from solution and added to the solution folder.
The above answer was not the perfect one as it doesn't work when the project is created under nested folders.
This is solved by giving a guid as solution folder name in the multiproject template and then looping through the projects in the solution to find the guid and rename the solution folder with the project name.
Posted the code here

Visual Studio 2012 multiple project template with inter-dependencies

I'm in the process of creating a MVC starterkit for work and I'm having problems creating a multi-project template that doesn't require massive manual modification after creation.
What I have is 4 projects that have some dependencies on each other:
StarterKit.Common - no dependency
StarterKit.DAL - dependency to StarterKit.Common
StarterKit.BL - dependency to StarterKit.Common and StarterKit.DAL
StarterKit.Web - dependency to the other three
I've tried going the route of exporting each project using the Export Template wizard, creating a root .vstemplate file and zipping it all up. Although this works (I can create a new solution based on this template), it has some serious problems.
Firstly, the export replaces the entire namespace of each project with $safeprojectname$, i.e. StarterKit.DAL => $safeprojectname$, StarterKit.Web => $safeprojectname$ etc.
This means that when the new project is created (let's call it XXX), what was previously in the namespace StarterKit.Web now ends up in the XXX namespace and what was previously StarterKit.BL also ends up in the XXX namespace!
This is obviously not going to work.
Secondly, some using statements are not replaced at all. For example using StarterKit.Common; is not replaced in the web project because it doesn't have the correct namespace (which is StarterKit.Web).
Thirdly, I have some .tt scripts that contains using statements I want to replace, but even though I set ReplaceParameters="true" in the project, these are not touched at all.
I also looked into creating a VSIX project, but frankly I don't see how I can use that. To me it looks mostly like a zip utility that creates the .vstemplate for you and renames the .zip to .vsix for me.
What I need to do is:
Package all the projects in a single deploy file available as a "New Project" template in VS
When a newproject is created, replace all "StarterKit" namespace references in .csproj, .cs, .cshtml and .tt files with whatever the user selected as the solution name
Figure out a simple process where I can easily update the templates whenever the base projects change (files added/removed, renamed, content changed etc)
Does anyone have any idea if this is even possible?
Full Disclosure: I am the creator of the below mentioned project.
You can achieve the desired result using the IWizard implementation I created called GlobalParams. It makes the information from the solution template level available to the child templates that also run the wizard by prefixing ALL solution level parameters with the word global and adding them to the parameters of the child template.
If you used GlobalParams with the above multi-project template and the user entered "StarterKit", the following would be true:
StarterKit.Common Could access
$safeprojectname$ = StarterKit.Common
$globalsafeprojectname$ = StarterKit
$globalguid1$ = E8C8A064601844439909D6C33AB90CB3
$globalguid2$ = 020DB5ABF76040C7BDA19EAC54DFE3D8
$globalguid3$ = 8392FB760F754C0AB87778845CC28B6D
$globalguid4$ = 13E07D43F523467587296B2C386DEE50
StarterKit.DAL
$safeprojectname$ = StarterKit.DAL
$globalsafeprojectname$ = StarterKit
$globalguid1$ = E8C8A064601844439909D6C33AB90CB3
$globalguid2$ = 020DB5ABF76040C7BDA19EAC54DFE3D8
$globalguid3$ = 8392FB760F754C0AB87778845CC28B6D
$globalguid4$ = 13E07D43F523467587296B2C386DEE50
StarterKit.BL
$safeprojectname$ = StarterKit.BL
$globalsafeprojectname$ = StarterKit
$globalguid1$ = E8C8A064601844439909D6C33AB90CB3
$globalguid2$ = 020DB5ABF76040C7BDA19EAC54DFE3D8
$globalguid3$ = 8392FB760F754C0AB87778845CC28B6D
$globalguid4$ = 13E07D43F523467587296B2C386DEE50
StarterKit.Web
$safeprojectname$ = StarterKit.Web
$globalsafeprojectname$ = StarterKit
$globalguid1$ = E8C8A064601844439909D6C33AB90CB3
$globalguid2$ = 020DB5ABF76040C7BDA19EAC54DFE3D8
$globalguid3$ = 8392FB760F754C0AB87778845CC28B6D
$globalguid4$ = 13E07D43F523467587296B2C386DEE50
With GlobalParams you have access to 100 Guids with the global prefix that are the same across child templates. So the StarterKit.Common project can be given the value of "$globalguid1$" as the project id with StarterKit.DAL and StarterKit.BL building project references to StarterKit.Common using "$globalsafeprojectname$.Common" as the name of the project being referenced and "$globalguid1$" as the id of the project being referenced. I think you can see how it will work for building the references between the rest of the projects.
I never found an answer to this, so I've chosen another route.
I've created a PowerShell script that I include in a zip file with the solution files. The script renames the solution, projects and classes according to a project name chosen by the user.
The bummer is that this has to be run outside Visual Studio

Header file inside the same solution

http://youtu.be/6NCtnKcwOas (select better quality!)
As you can see on the attached video, I have the two projects in my solution - a dll creator and a simple testing project. Just followed this tutorial .
Why does the MathFuncsDll.h still remain undetected?Everything works fine after specifying the full path after '#include'. However, I don't want to use such rough-and-ready method because it looks messy and unprofessionally.
If you can specify the file using an absolute path, but not by only using its filename, the compiler doesn't "know" about the folder containing that file.
You can tell the compiler about your additional include directories via the /I directive (documentation). And of course you can set that via the IDE.