1

我想为 Visual Studio 扩展安装设计时插件(即在使用 Visual Studio 时运行,而不是在应用程序运行时运行)。这要求我使用指向包含扩展代码的 dll 的条目来修改 app.config。该插件是通过 nuget 安装的,如果我将此 dll 添加到项目下的文件夹并在 app.config.install.xdt 中使用固定路径,那么一切正常。但是我想要的是让 xdt 插入一个指向包文件夹中的 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 正确配置?

4

1 回答 1

0

XDT 语法不允许替换标记,例如您在示例中放置的标记。

我能想到的一种选择是修改init.ps1 PowerShell 脚本中的app.config.install.xdt文件,在NuGet 应用 XDT 转换之前替换实际值的标记。

有关 init.ps1 的更多信息,请参阅:创建和发布包

于 2016-06-17T18:19:20.907 回答