I'm working with a monolith that uses a traversal build to build a set of projects that are available to us developers in a set of different solution files. I'm now trying to get NCrunch working with these solutions. I was able to include the necessary property files which allowed the build to proceed to the point where it's attempting to restore NuGet packages, at which point it failed.
In investigating, I discovered the following but am not sure how to implement the needed changes in NCrunch:
The generated csproj file looks good to me
The build fails because no NuGet package references are resolved
The NuGet package references aren't resolved because no project.assets.json file is present in the obj directory
The build fails against the generated csproj on the command line in the same way the build fails for NCrunch
If I do either of the following, the build succeeds:
dotnet restore -r win -r win-x64 -r win-x86
Add <RuntimeModifiers>win;win-x64;win-x86</RuntimeModifiers> to the first PropertyGroup in the csproj, and then do a nuget restore
So, given that the underlying problem is that I don't have the assets file and once I do have the assets file I need to ensure it's built for the right runtimes, how do I go about getting NCrunch properly configured?
NCrunch should normally detect the project.assets.json file (along with its related 'obj' files) and copy this into the workspace with some minor manipulation. How are your projects structured in regards to project.assets.json? Is the file present? Given your description of this solution, I'm wondering if perhaps there is a customisation of some kind in place that is putting the project.assets.json file in a place where NCrunch isn't able to detect it. Are you able to find the file inside your foreground solution? If not, how is it that your foreground build is able to work without the file present? This may involve some kind of build feature that I don't yet have knowledge of.
NCrunch should normally detect the project.assets.json file (along with its related 'obj' files) and copy this into the workspace with some minor manipulation. How are your projects structured in regards to project.assets.json? Is the file present?
It is present in the foreground build but not in the NCrunch copy. Out of curiosity, I added the project.assets.json file as an additional Include file for the first project in my solution after which point the build for that project completed. The output is below, which should give you an idea of the structure:
Remco wrote:
Given your description of this solution, I'm wondering if perhaps there is a customisation of some kind in place that is putting the project.assets.json file in a place where NCrunch isn't able to detect it. Are you able to find the file inside your foreground solution? If not, how is it that your foreground build is able to work without the file present? This may involve some kind of build feature that I don't yet have knowledge of.
I'm currently including a number of additional files using the Include directive. They are as follows:
Solution1/Directory.Build.props
Tools/Build/Build.Common.targets
Tools/Build/Build.props
build.root
Here's the set of properties that control the various output paths, one of which is likely the culprit:
<PropertyGroup>
<RootBinDir>$(__RootBinDir)\</RootBinDir>
<RootBinDir Condition="'$(__RootBinDir)'==''">$(BuildRoot)Output\</RootBinDir>
<!-- This property is used in the various projects to reference built assemblies -->
<OutBin>$(__OutBin)\</OutBin>
<OutBin Condition="'$(__OutBin)'==''">$(RootBinDir)bin\$(BuildArch).$(BuildType)\</OutBin>
<BinDir>$(__BinDir)\</BinDir>
<BinDir Condition="'$(__BinDir)'==''">$(OutBin)$(Component)\</BinDir>
<BinDir Condition="'$(IsolateComponents)'=='true'">$(BinDir.TrimEnd('\'))\$(MSBuildProjectName)</BinDir>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'==''">$(RootBinDir)obj\$(Component)\$(MSBuildProjectName)</BaseIntermediateOutputPath>
<__IntermediatesDir Condition="'$(__IntermediatesDir)'==''">$(BaseIntermediateOutputPath)\$(BuildArch).$(BuildType)\</__IntermediatesDir>
<IntermediateOutputPath Condition="'$(IntermediateOutputPath)'==''">$(__IntermediatesDir)\</IntermediateOutputPath>
<IntDir>$(IntermediateOutputPath)</IntDir>
<OutputPath>$(BinDir)</OutputPath>
<OutDir>$(OutputPath)</OutDir>
<OutDir Condition="!HasTrailingSlash($(OutDir))">$(OutDir)\</OutDir>
</PropertyGroup>
Please let me know what other information I can provide, and thank you for your help troubleshooting this!
Remco wrote: ... Can you try using ProjectName instead of MSBuildProjectName when overriding the BaseIntermediateOutputPath property?
Yes, that fixed it!
We did have a mix of non-SDK style projects and with other SDK style projects. About half way through the solution NCrunch failed to build the remaining non-SDK style projects it encountered, but I migrated those over to SDK style projects and then everything picked up and built properly.