$ SpecificSolutionName $始终为空.如何判断用户是否在创建新的解决方案目录? [英] $SpecificSolutionName$ is always empty. How can I tell if the user is making a new solution directory or not?

查看:108
本文介绍了$ SpecificSolutionName $始终为空.如何判断用户是否在创建新的解决方案目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Visual Studio 2017中,使用IWizard界面创建C#项目模板项目,我向用户弹出自定义对话框,但无法确定他们以前是否选择了为解决方案创建目录"复选框.在生成Project对象之前,我仍然需要在RunStarted()接口函数中知道这一点(换句话说,我不能使用project.DTE.Solution).

In Visual Studio 2017, creating a C# Project Template project with the IWizard interface, I pop up my customised dialog to the user but I can't determine whether they've previously selected the "Create Directory For Solution" checkbox. I need to know this while still in the RunStarted() interface function, before the Project object is generated (in other words, I can't use project.DTE.Solution).

Microsoft很棒的文档说我可以看看 $ SpecificSolutionName $ ,但对我来说总是空白.

Microsoft's awesome documentation says I can just look at $SpecificSolutionName$, but it's always coming up empty for me.

同时,其他 StackOverflow

Meanwhile, other StackOverflow questions are either referring to multi-project templates, or just don't have an answer. My particular problem is a simple, one-project template.

我也尝试了$ SolutionName $.经过数天令人疲惫的Google精疲力尽之后,我放弃了,不得不捏造事物.如果我不必猜测期望的解决方案文件夹的名称(如果有的话),那就太好了.更糟糕的是,要确定 does-it-even-exist 解决方案文件夹是否是新的,我发现自己正在比较文件夹的创建日期.事情开始达到大量的变通办法.

I've also tried $SolutionName$. After some frustrating days of exhausting Google, I gave up and have had to fudge things. It would be nice if I didn't have to make guesses for the name of the expected solution folder, if there is one. Worse still, to determine whether the does-it-even-exist solution folder is new or not I find myself comparing folder creation dates. Things are starting to reach a critical mass of hacky workarounds.

问:如何在项目模板向导的RunStarted()中找到解决方案文件夹名称,或者至少找到用户是否选择创建新的解决方案文件夹?

推荐答案

我了解到我可以附加到进程..." VS的临时实例并对其进行调试.因此,我不得不看一下replacesDictionary对象.

I learnt that I can just "Attach to Process... " the temporary instance of VS and debug that. So I got to have a look at the replacementsDictionary object.

与所有文档所说的相反,所需的模板参数实际上是:

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

$ SpecifiedSolutionName $

...而不是"SpecificSolutionName".

... and not "SpecificSolutionName".

这已经解决了一半的难题,但是不要让这激发您的兴趣. SpecifiedSolutionName 也不执行文档所说的操作.

That's half the mystery solved but don't let this excite you. SpecifiedSolutionName also doesn't do what the docs say it does.

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

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

未选中创建解决方案目录"时,SpecificSolutionName [sic] 为空白.

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

否.未选中创建解决方案目录"时,$ SpecifiedSolutionName $包含$ projectname $中的任何内容.

Nope. When "create solution directory" is not checked, $SpecifiedSolutionName$ contains whatever is in $projectname$.

如果这不是解决方案目录和项目目录具有相同名称的默认行为,那对我们就足够了.但是,由于这种情况很常见,因此这个$ SpecifiedSolutionName $值无法告诉我们用户是否创建了新的解决方案目录.

That would be enough for us if it wasn't for the fact that it is default behaviour for a solution directory and project directory to have the same name. But since that's a common occurrence, this $SpecifiedSolutionName$ value can't tell us whether the user created a new solution directory or not.

因此,我仍然看不到直接报告用户是否已选中该复选框的任何内容.不过,由于另一个名为 $ solutiondirectory $ 的模板参数,您可以跳过一些逻辑.

So I still see nothing that directly reports whether the user ticked or unticked that checkbox. There is some logic you can jump through however, thanks to another template parameter called $solutiondirectory$.

哪一个也坏了.

如果用户勾选为解决方案创建目录",则$ solutiondirectory $是将保存解决方案文件的目录.如果用户取消选择为解决方案创建目录",则$ solutiondirectory $是用于保存解决方案文件的目录,因此文件系统可能比您关心的位置高.

If the user ticks "Create directory for solution", then $solutiondirectory$ is the directory that will hold the solution file. If the user unticks "Create directory for solution", then $solutiondirectory$ is the directory that holds the directory that will hold the solution file, and is thus probably higher up the filesystem than you care about.

$ solutiondirectory $ 报告的实际上实际上只是 $ destinationdirectory $ \ .. \..也就是说,该目录上方的目录将保存 project 文件.不论是否勾选了为解决方案创建目录", $ solutiondirectory $ 参数都在乎项目的文件&目录,而不是解决方案的目录.

What $solutiondirectory$ reports is actually just $destinationdirectory$\..\. That is, the directory above the directory that will hold the project file. It doesn't matter if "Create directory for solution" was ticked or not, the $solutiondirectory$ parameter cares about the project's file & directory, not the solution's.

回到问题所在,当解决方案和项目名称相同时,我们如何知道用户是否勾选了为解决方案创建目录"?

So back to the question, how do we know if the user has ticked "Create directory for solution", when solution and project might both have the same name?

在这种情况下,两个错误几乎是对的.将 $ SpecifiedSolutionName $ $ solutiondirectory $ 中的最终路径元素进行比较.如果这些不同,则用户肯定会取消选中创建解决方案目录". (因为前者将是项目名称,而后者将是文件系统中更高的名称.)

Two wrongs almost make a right in this case. Compare $SpecifiedSolutionName$ to the final path element in $solutiondirectory$. If these are different, the user has definitely unticked "Create directory for solution." (Because the former will be the project name, and the latter will be whatever the filesystem has a bit higher up.)

如果它们相同,则用户可能已勾选了该框.但是还有另一件事要考虑.也许出于某种原因,所有这些之上的目录也与项目和/或解决方案目录具有相同的名称.这样的用户可能很奇怪.我不知道有什么可靠的方法可以解决这种情况(也许有更多名称相同的目录),所以我只是把它留作注意.

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

这篇关于$ SpecificSolutionName $始终为空.如何判断用户是否在创建新的解决方案目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆