在应用xdt时,我可以获取当前解决方案的packages文件夹的位置吗?

时间:2016-06-06 13:30:48

标签: nuget nuget-package-restore xdt-transform

我想为visual studio扩展安装一个设计时插件(即在使用visual studio时运行,而不是在应用程序运行时运行)。这要求我使用指向包含扩展代码的dll的条目修改app.config。该插件是通过nuget安装的,如果我将这个dll添加到项目下的文件夹中,并在app.config.install.xdt中使用固定路径,那么一切正常。但是我想要的是xdt插入一个值,该值指向packages文件夹中的dll,它通过nuget安装。我的问题是nuget文件夹的相对路径不是固定的项目。每个项目可能位于不同的文件夹(解决方案文件夹内的几个文件夹),而不仅仅是解决方案文件夹的直接子项,因此我希望能够在我的xdt中使用某个变量。

目前我的xdt中有这个:

<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <specFlow>
    <plugins xdt:Transform="InsertIfMissing">
      <add name="NCrunch.Generator" path=".\SpecflowPlugins\" type="Generator" xdt:Transform="InsertIfMissing" xdt:Locator="Match(name)"/>
    </plugins>
  </specFlow>
</configuration>

但我想要这样的事情:

<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <specFlow>
    <plugins xdt:Transform="InsertIfMissing">
      <add name="NCrunch.Generator" path="$(SolutionDir)\packages\Specflow.Ncrunch.1.0.0\lib\net" type="Generator" xdt:Transform="InsertIfMissing" xdt:Locator="Match(name)"/>
    </plugins>
  </specFlow>
</configuration>

这可能在xdt中吗?如果没有,当我的nuget包安装时,是否有另一个选项可以正确地使用app.config?

1 个答案:

答案 0 :(得分:0)

XDT语法不允许替换令牌,例如您在示例中添加的令牌。

我能想到的一个选项是修改 init.ps1 PowerShell脚本中的 app.config.install.xdt 文件,替换实际的令牌NuGet应用XDT变换之前的值。

有关init.ps1的详细信息,请参阅:Creating and Publishing a Package

相关问题