【问题标题】:Avoid copying content files to output with VisualStudio / MSBuild避免使用 VisualStudio / MSBuild 将内容文件复制到输出
【发布时间】:2021-08-10 01:37:05
【问题描述】:

我正在开发一个 C# .NET 5.0 SDK 风格的项目,该项目使用在运行时动态加载的插件。有一个主项目,每个插件都有一个项目。插件构建过程的输出包括一些内容文件(一个 json 配置文件和一个徽标图像)。主项目和插件都在同一个解决方案中。

内容文件在插件项目中表示如下:

<ItemGroup>
    <Content Include="logo.jpg">
        <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <Content Include="plugin.json">
        <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
</ItemGroup>

我想让构建主项目在必要时也构建插件,但在主项目输出中不包含任何插件构建输出。为此,我在主项目中添加了对插件项目的引用,如下所示:

<ItemGroup>
    <ProjectReference Include="..\Plugin1\Plugin1.csproj">
        <ReferenceOutputAssembly>false</ReferenceOutputAssembly>
    </ProjectReference>
    <ProjectReference Include="..\Plugin2\Plugin2.csproj">
         <ReferenceOutputAssembly>false</ReferenceOutputAssembly>
    </ProjectReference>
    <!-- etc. -->
</ItemGroup>

这对插件 DLL 可以正常工作(它们不包含在主项目输出中),但它不适用于插件内容文件(它们正在包含在主项目输出中)。

我尝试将&lt;CopyToOutputDirectory&gt;Never&lt;/CopyToOutputDirectory&gt;&lt;OutputItemType&gt;None&lt;/OutputItemType&gt; 添加到项目引用中,但都没有任何效果。

知道如何防止内容文件包含在主项目输出中吗?

【问题讨论】:

    标签: c# msbuild csproj


    【解决方案1】:

    您应该能够使用:

    <ItemGroup>
      <ProjectReference Include="..\Plugin1\Plugin1.csproj"
        ReferenceOutputAssembly="False"
        Private="False" />
    </ItemGroup>
    

    【讨论】:

    • 成功了,谢谢。如果 VisualStudio intellisense 像我提到的其他事情一样将它作为一个选项包括在内,那就太好了。
    猜你喜欢
    • 2018-03-28
    • 2016-08-15
    • 2012-10-11
    • 1970-01-01
    • 1970-01-01
    • 2020-08-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多