为什么我的 VSIX 解决方案的构建和重建没有生成相同的输出

Why are build and rebuild of my VSIX solution not generting the same output

我的项目是一个 Visual Studio 扩展。该解决方案包含多个项目并引用多个 NuGet 包。我使用的是 visual studio 2019 版本 16.2.1,我使用的是 Microsoft.VSSDK.BuildTools 版本 16.2.3073.

如果我重建整个项目,或者如果我在构建之前清理解决方案,似乎一切都已正确构建。

但是,如果我在没有先清理的情况下构建解决方案,VSIX 安装中至少会省略一个 dll。这个特定的 DLL 是二级项目引用的输出。

我的顶级 VSIX 项目是 MultiLanguageWPF。这具有对 MultiLanguageLegacy 的项目引用,后者又具有对 MultiLangCodeParser 的项目引用。生成后 VSIX 中缺少文件 MultiLangCodeParser.dll。

MultiLanguageWPF
| 
+-- MultiLanguageLegacy
    | 
    +-- MultiLangCodeParser

我使用 F5 启动调试器时出现同样的问题,除非我先清理项目(这特别烦人)。

如何防止构建和重建的这种不同行为?

顺便说一下,构建我的解决方案总是构建顶级项目 MultiLanguageWPF,即使它刚刚构建。

If I rebuild the complete project, or if I clean the solution before building, everything seems to be built correctly.

是的,解决方案构建良好并且是预期的行为。参见 this,重建为 clean+build,因此这两种方式都可以正常工作。无论 rebuild 还是 clean and build,它们都会以这种方式构建您 solution.In 中的所有项目,MultiLangCodeParser.dll 可以被 MultiLanguageWPF 识别并将其包含在 vsix 包中。

However, if I build the solution without cleaning it first, at least one dll is omitted from the VSIX installation. This specific DLL is the output of a second level project reference.

如果我在 MultiLanguageWPF 项目中更改某些内容,现在构建解决方案,因为我没有对 MultiLanguageLegacyMultiLangCodeParser 进行任何更改,VS 不会实际构建这两个项目,它只会构建顶级MultiLanguageWPF项目本身,类似这样:

当vs只构建顶层工程而不重建一二级工程时,构建引擎只会从MultiLanguageWPF.csproj中读取内容,在这个文件中它只定义了对[=的包引用16=],因此它将在 .vsix 中包含 MultiLanguageLegacy.dll,但不会复制 MultiLangCodeParser.dll,因为在这种情况下构建引擎不知道 MultiLanguageLegacy.dll 依赖于 MultiLangCodeParser.dll.它没有从MultiLanguageLegacy.csproj读取数据并构建它,所以如果引擎只构建顶级项目,我认为它不会知道一级和二级项目之间的依赖关系.

解决方法:

我可以重现同样的问题,它确实存在,您当前解决方案的解决方法是将下面的脚本添加到 MultiLanguageWPF.csproj 中:(假设您的三个项目位于 相同的解决方案文件夹中)

  <Target Name="AddCustomItem" AfterTargets="GetVsixSourceItems">
    <ItemGroup>
      <VSIXSourceItem Include="..\MultiLangCodeParser\bin$(Configuration)\MultiLangCodeParser.dll" />
    </ItemGroup>
  </Target>

然后这个恼人的问题似乎在我的机器上消失了。