I have an C# app app that is loading plugins, during development phase I want to have them copied to app output directory with their dependencies so I can debug easily. I have a task in the app csproj that takes care of it.
<Target Name="CopyPlugins" BeforeTargets="Build">
<ItemGroup>
<PluginProject Include="..\Plugins\Example\Example.csproj" />
<PluginProject Include="..\Plugins\ExampleWithDependencies\ExampleWithDependencies.csproj" />
</ItemGroup>
<MSBuild Projects="@(PluginProject)" Targets="Restore" />
<MSBuild Projects="@(PluginProject)" Targets="Build" />
<MSBuild Projects="@(PluginProject)" Targets="Publish" Properties="PublishDir=$(TargetDir)" />
</Target>
That works like a charm for plugins that are not referencing any libs that needs to be built. For projects tha are having dependencies than need to be built, I'm getting error during executing the Build target: error CS0006: Metadata file 'D:\my\project\path\Plugins\Libs\SomeDependencyLib\obj\x64\Debug\net8.0\ref\SomeDependencyLib.dll' could not be found
To me it looks like the nested referenced projects are not being buit, if I compile such project explicitely, then the app task succeeds.
Any hint how to enforce building project with its dependencies via MSBuild task?
Updates from experimenting:
- it happens only from withing Visual Studio, when running it on commandline with VS MSBuild, it works as expected
- Looks like it tries to build referenced projects but those fail due definitions to generate AssemblyInfo values that are defined in
Directory.Build.propsfile that is on solution level