Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual studio project template creating solution file in outer directory

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.

like image 590
Jenish Rabadiya Avatar asked Dec 31 '14 06:12

Jenish Rabadiya


2 Answers

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

like image 53
elchido Avatar answered Oct 19 '22 01:10

elchido


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

like image 36
Carlo Luther Avatar answered Oct 19 '22 03:10

Carlo Luther