I am working on a C# .NET 5.0 SDK-style project that uses plugins that are dynamically loaded at runtime. There is a main project, and a project for each plugin. The output of the plugins build process includes some content files (a json configuration file and a logo image). The main project and plugins are all in the same solution.
The content files are represented in the plugin projects like so:
<ItemGroup>
<Content Include="logo.jpg">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="plugin.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
I want to make it so that building the main project also builds the plugins if necessary, but does not include any of the plugin build output in the main project output. To accomplish this, I added references to the plugin projects to the main project as follows:
<ItemGroup>
<ProjectReference Include="..\Plugin1\Plugin1.csproj">
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
</ProjectReference>
<ProjectReference Include="..\Plugin2\Plugin2.csproj">
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
</ProjectReference>
<!-- etc. -->
</ItemGroup>
This works as expected for the plugin DLLs (they are not included in the main project output), but it does not work for the plugin content files (they are being included in the main project output).
I have tried adding <CopyToOutputDirectory>Never</CopyToOutputDirectory>
and <OutputItemType>None</OutputItemType>
to the project references, but neither has had any effect.
Any idea how to prevent the content files from being included in the main project output?
You should be able to accomplish this using:
<ItemGroup>
<ProjectReference Include="..\Plugin1\Plugin1.csproj"
ReferenceOutputAssembly="False"
Private="False" />
</ItemGroup>