2

I have three projects, I will call them ProjectSource, ProjectProcessor and ProjectTarget

ProjectSource is a .NET Standard 2.0 library producing a DLL.

ProjectProcessor is a .NET Core 2.1 console library. ProjectProcessor has a project reference on ProjectSource. It loads the ProjectSource DLL and based on some types it finds in there generates some output files (lets just say they are documentation). The number of files it produces can change over time.

ProjectTarget is a .NET Framework 4.7.1 console application. It has a dependency on ProjectSource, but also needs to include the content output by ProjectProcessor.

All projects are our code so we could change them quite a bit.

My question is, what is the right way to get the content output files of ProjectProcessor written to the output directory of ProjectTarget?

Approach 1: One approach that did not work was to use project reference in ProjectTarget to ProjectProcessor. It produced a build error that a .NET Framework 4.7.1 console application referencing a .NET Core 2.1 console library. I wouldn't want all the project output copied anyway, just the generated documentation files. I did try a ProjectReference with ReferenceOutputAssembly="false" and OutputItemType="Content".

Approach 2: Another approach is to have a pre or post build step on ProjectTarget that calls the ProjectProcessor console application, passing in the current target directory (of ProjectTarget). For example:

<PropertyGroup> <PreBuildEvent>dotnet $(SolutionDir)projects\ProjectProcessor\$(OutDir)netcoreapp2.1\ProjectProcessor.dll $(TargetDir)</PreBuildEvent> </PropertyGroup>

This works, with the unfortunat downside that it doesn't recognize when it needs to run (I think it'd always run?). If ProjectSource or ProjectProcessor have code changes I'd like it to run again, but not otherwise. (based on MSBuild copy output from another project into the output of the current project)

Approach 3: Finally, googling led me to try adding a target like this:

<Target Name="GenerateDocumentationContent" BeforeTargets="AfterBuild"> <MSBuild Projects="..\ProjectProcessor\ProjectProcessor.csproj" BuildInParallel="false" Targets="Build"> <Output TaskParameter="TargetOutputs" ItemName="DocumentationOutputDir" /> </MSBuild> <Exec Command="dotnet @(DocumentationOutputDir) $(TargetDir)"/> </Target>

This builds the ProjectProcessor project as expected and calls the resulting console application with the right parameters. But it doesn't run in the case that ProjectTarget doesn't have changes and I want it to run if ProjectSource and ProjectProcessor have changes.

Frank Schwieterman
  • 24,142
  • 15
  • 92
  • 130

0 Answers0