The problem is, that the first ItemGroup (Condition="'$(MSBuildProjectFile)'!='SolutionItems.csproj'">) works as expected, all project files have a link to AssemblyDefaults.cs and CustomDictionary.xml.
The second ItemGroup (Condition="$(MSBuildProjectFile.Contains('Audit.Test.csproj')) And !$(MSBuildProjectFile.Contains('TestHelpers.csproj')) does not work.
NCrunch gives us the following error:
CSC (0, 0): Source file 'C:\Temp\NCrunch\38704\StrauplanManager\Src\PPMS\v\1.06\Upper.PrintProcessingManager.TestHelpers\FluentAssertionsGlobalConfiguration.cs' could not be found.
VS 2022 does work and shows no errors during compilation (also the link shows up correctly), so it seems the second item group is correct.
Why does the first ItemGroup work but not the second one?
Is there a way to tell NCrunch to copy the FluentAssertionsGlobalConfiguration.cs from Upper.PrintProcessingManager.TestHelpers
Here is a simplified version of our directory.build. props
NCrunch has some limitations in what it can handle in the Directory.build.props file. Notably, when it loads your project, it does so under a different project name (i.e. _nCrunchTemp_....). This means that certain MSBuild properties (such as $(MSBuildProjectFile)) will return an unexpected result under NCrunch.
I suspect the reason your file is not being identified is because of the above limitation. I would suggest working around this by finding a different way to identify the projects that need to have this file included, perhaps by introducing a custom property.
Another thing that may work here is to simply include the FluentAssertionsGlobalConfiguration.cs file in your solution-level additional files to include.
NCrunch has some limitations in what it can handle in the Directory.build.props file. Notably, when it loads your project, it does so under a different project name (i.e. _nCrunchTemp_....). This means that certain MSBuild properties (such as $(MSBuildProjectFile)) will return an unexpected result under NCrunch.
I suspect the reason your file is not being identified is because of the above limitation. I would suggest working around this by finding a different way to identify the projects that need to have this file included, perhaps by introducing a custom property.
Another thing that may work here is to simply include the FluentAssertionsGlobalConfiguration.cs file in your solution-level additional files to include.
Another question: is it possible to add a project reference via directory.build.props when using NCrunch, or isn't it supported at all?
UppSol wrote:
Another question: is it possible to add a project reference via directory.build.props when using NCrunch, or isn't it supported at all?
Unfortunately we can't support project references inside directory.build.props. This is because the file is outside the scope of our manipulation, and we heavily manipulate the project references when building workspaces for projects.