8

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:

enter image description here

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:

enter image description here

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.

Jenish Rabadiya
  • 6,708
  • 6
  • 33
  • 62

4 Answers4

1

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

enter image description here

folder DDD_Backend10xxxx, contains all the projects:

enter image description here

step 1: Move the .sln file in the sub folder containing all the projects (as required for project to work):

enter image description here

*.sln file moved to same folder with the rest of the projects

enter image description here

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.

enter image description here

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.)

Carlo Luther
  • 2,402
  • 7
  • 46
  • 75
  • 1
    Thank you for your answer. I had already thought of this way to resolve the issue but I wanted to make it fully automated where this solution requires manual changes to the sln file. – Jenish Rabadiya May 24 '17 at 06:35
1

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).

elchido
  • 153
  • 7
0

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.

DrWicked
  • 31
  • 3
-2

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.

Mothbawls
  • 120
  • 4
  • No I am not creating only one project MVC1. All the project that is in the screenshot 1 is inside MVC1 folder of screenshot2. Does that make sense? xml I provided is the one that groups all the project. – Jenish Rabadiya Feb 20 '15 at 04:39
  • 3
    Well, you obviously didnt read the question properly. What the threadstarter is saying is that there is an additional folder created, that is not reflected in the vstemplate file. – Konstantin Chernov Jul 20 '15 at 10:13
  • Ahh, I misunderstood. Sorry about that! – Mothbawls Sep 02 '15 at 16:23