$ SpecificSolutionName $ is always empty. How do I know if a user is creating a new solution directory or not?

In Visual Studio 2017, by creating a C # Project Template with an IWizard interface, I bring up my customized dialog to the user, but I cannot determine if the New Directory for Solution checkbox was previously selected. I need to know this while still in the RunStarted () interface function, before creating the Project object (in other words, I cannot use project.DTE.Solution).

The wonderful Microsoft documentation says that I can just look at $ SpecificSolutionName $ , but it always gets empty for me.

Meanwhile, other StackOverflow questions are either linking to multi-draft templates or just donning I have an answer. My particular problem is a simple one-project template.

I have also tried $ SolutionName $. After some frustrating days of tedious Google, I gave up and had to figure things out. It would be nice if I didn't have to guess the name of the expected solution folder, if there is one. Worse, in order to determine if the solution folder is "still there" or not, I find myself comparing the folder creation dates. Things are starting to reach a critical mass of hacky workarounds.

Q: How do I find the name of the solution folder, or at least was the user selected to create a new solution folder inside the RunStarted () of the Project Template Wizard?

0


source to share


2 answers


I found out that I can just "Attach to Process ..." a temporary VS instance and debug it. So I have to look at the replacementsDictionary object.

Contrary to what all the docs say, the required template parameter is:

$ SpecifiedSolutionName $

... not "SpecificSolutionName".

This mystery has been solved, but don't let that worry you. SpecifiedSolutionName also doesn't do what the docs say.

From https://docs.microsoft.com/en-us/visualstudio/ide/template-parameters :

When "create solution directory" is not checked, SpecificSolutionName [sic] is empty.

Not. When "create solution directory" is not checked, $ SpecifiedSolutionName $ contains everything in $ projectname $.

This would be enough for us if it weren't for the fact that this is the default behavior for the solutions directory and the projects directory of the same name. But since this is a common occurrence, this $ SpecifiedSolutionName $ value cannot tell us whether the user has created a new solution directory or not.



So, I still don't see anything that directly tells whether the user has been checked or not checked. There is some logic you can jump over, however, thanks to another template parameter called $ solutiondirectory $ .

Which is also violated.

If the user specifies "Create directory for solution", then $ solutiondirectory $ is the directory where the solution file will be stored. If the user opts out of "Create directory for solution" then $ solutiondirectory $ is the directory that contains the directory where the solution file will be stored, and hence it is probably higher than the filesystem than you want.

Which reports $ solutiondirectory $ is really just $ destinationdirectory $ \ .. \. That is, the directory above the directory where the project file will be stored. It doesn't matter if "Create Solution Directory" was checked or not, the $ solutiondirectory $ parameter takes care of the project file and directory, not the solution.

So back to the question, how do we know that the user checked "Create directory for solution" when the solution and the project can have the same name?

In this case, two mistakes are almost right. Compare $ SpecifiedSolutionName $ to the end element of the path in $ solutiondirectory $ . If they are different, the user has definitely turned off "Create directory for solution". (Because the first will be the name of the project, and the last will be that the filesystem is slightly higher.)

If they match, the user may check this box. But there is one more thing to consider. Perhaps for some reason, the directory above it all also has the same name as the project and / or solution directory. Users can be weird. I don't know the right way to account for this situation (there are probably more directories with the same name), so I just leave this as something to be aware of.

0


source


Finally, for a multi-project solution, here is what got me working: -

Solution template (multi-project): -

<TemplateContent>
    <ProjectCollection>
        <ProjectTemplateLink ProjectName="$safeprojectname$.WebApp">
            WebApp\MyTemplate.vstemplate
        </ProjectTemplateLink>   .....

      

Code level changes



namespace $safeprojectname$

      

In connection with the first step, the project name now includes the solution name. At the project level, the namespace and assembly name should ideally be the same, without any requirements for their placement.

Let me know if this helps

0


source







All Articles