Build/Test Issues

Directory.build.props - Add a link to certain projects fails

Started by UppSol on 4,965 views

Hi,

Please have a look at the directory.build.props

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
<PropertyGroup Label="Globals">
     <TargetFramework Condition="!$(MSBuildProjectFile.Contains('.sqlproj'))">net6.0</TargetFramework>
    <Nullable>enable</Nullable>
    <DebugType>Embedded</DebugType>
    <EmbedAllSources Condition="'$(Configuration)' == 'Debug'">True</EmbedAllSources>
    <ImplicitUsings>enable</ImplicitUsings>
 

  <!-- Add links to all projects, except SolutionItems -->
  <ItemGroup Condition="'$(MSBuildProjectFile)'!='SolutionItems.csproj'">
    <Compile Include="$(SolutionDir)\SolutionItems\Common\AssemblyDefaults.cs" Link="Properties\AssemblyDefaults.cs" />
    <Content Include="$(SolutionDir)\SolutionItems\Common\CustomDictionary.xml" Link="Properties\CustomDictionary.xml" />
  </ItemGroup>

  <ItemGroup Condition="$(MSBuildProjectFile.Contains('Audit.Test.csproj')) And !$(MSBuildProjectFile.Contains('TestHelpers.csproj'))">
    <Compile Include="$(SolutionDir)Upper.PrintProcessingManager.TestHelpers\FluentAssertionsGlobalConfiguration.cs" Link="FluentAssertions\FluentAssertionsGlobalConfiguration.cs" />
  </ItemGroup>

</Project>

Edited

Hi, thanks for sharing this issue.

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.
Remco wrote:Hi, thanks for sharing this issue.

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?

Br
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.

Post a reply

Log in to reply.