0

UPDATE: I was able to get this working by setting "ProduceReferenceAssembly" to false in the .csproj files of the libs. Not sure if this is optimal or intended but that is what worked for me. See: Ref folder within .NET 5.0 bin folder

I'm trying to set up a proof of concept using NX dot net and Azure using this exaple .yml: https://nx.dev/recipes/ci/monorepo-ci-azure

I have 3 services (libs) and 3 apis (apps) ... I made a change to one of the apis to test caching and incremental builds.

The unchanged projects all say [remote cache] but then the build fails because it's looking for the .dlls in the /obj/Debug/ directory. Why use that when there are .dlls in the /dist directory?

How can I fix this? Is there something in the nx.json or project.json files I need to change?

(https://i.stack.imgur.com/IQhaO.png)

I tried using the same command locally on my machine and it completes as expected. I expect the build to complete. The build fails when remote caching is used.

{
  "name": "ShipmentService",
  "$schema": "../../node_modules/nx/schemas/project-schema.json",
  "projectType": "library",
  "sourceRoot": "libs/ShipmentService",
  "targets": {
    "build": {
      "executor": "@nx-dotnet/core:build",
      "outputs": [
        "{workspaceRoot}/dist/libs/ShipmentService",
        "{workspaceRoot}/libs/ShipmentService/obj"
      ],
      "options": {
        "configuration": "Debug",
        "noDependencies": true
      },
      "configurations": {
        "production": {
          "configuration": "Release"
        }
      }
    },
    "lint": {
      "executor": "@nx-dotnet/core:format"
    }
  },
  "tags": []
}

Tried proposed workaround, here's what I'm noticing: platformservice:build [remote cache]

Error, it sees the intermediates part, but basically same issue: same error

Updated project.json (all of them have been updated to look similar to this [tried with and without /obj portion]):

 "outputs": [
        "{workspaceRoot}/dist/libs/ShipmentService",
        "{workspaceRoot}/dist/intermediates/libs/ShipmentService/obj"
      ],
Jason
  • 1
  • 1

1 Answers1

0

This is a bug on nx-dotnet's side, and we aren't quite capturing all of the outputs that are needed for the cache. If you add the path to the obj directory into the outputs array of the build target in project.json it should work. Here's the workaround which will eventually be migrated:

I've got a branch with this working, you do indeed need the obj directory as part of the cache. There are some weird intricacies with this though. I'll work on a migration + patch. In the meantime, the workaround that I used is:

Update Directory.Build.props adding these to the property group containing the output path manipulation:

    <BaseIntermediateOutputPath>$(RepoRoot)dist/intermediates/$(ProjectRelativePath)/obj</BaseIntermediateOutputPath>
    <IntermediateOutputPath>$(BaseIntermediateOutputPath)</IntermediateOutputPath>

As an example, the full file looks like this on the nx-dotnet repo now:

<Project>
  <PropertyGroup>
    <!-- Output path configuration -->
    <RepoRoot>$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)'))</RepoRoot>
    <ProjectRelativePath>$([MSBuild]::MakeRelative($(RepoRoot), $(MSBuildProjectDirectory)))</ProjectRelativePath>
    <BaseOutputPath>$(RepoRoot)dist/$(ProjectRelativePath)</BaseOutputPath>
    <OutputPath>$(BaseOutputPath)</OutputPath>
    <BaseIntermediateOutputPath>$(RepoRoot)dist/intermediates/$(ProjectRelativePath)/obj</BaseIntermediateOutputPath>
    <IntermediateOutputPath>$(BaseIntermediateOutputPath)</IntermediateOutputPath>
    <AppendTargetFrameworkToOutputPath>true</AppendTargetFrameworkToOutputPath>
  </PropertyGroup>
  <PropertyGroup>
    <RestorePackagesWithLockFile>false</RestorePackagesWithLockFile>
  </PropertyGroup>
</Project>

Your project.json file should look something like this now:

{
  "name": "demo-webapi",
  "sourceRoot": "demo/apps/webapi",
  "targets": {
    "build": {
      "executor": "@nx-dotnet/core:build",
      "outputs": [
        "{workspaceRoot}/dist/demo/apps/webapi",
        "{workspaceRoot}/dist/intermediates/demo/apps/webapi"
      ],
      "options": {
        "configuration": "Debug",
        "noDependencies": true
      },
      "configurations": {
        "production": {
          "configuration": "Release"
        }
      }
    }
  }
}

Craigory Coppola
  • 647
  • 4
  • 13
  • Added a sample project.json above adding obj directory with no luck. – Jason Jan 24 '23 at 19:15
  • Can you try to make the changes detailed above? You may need to invalidate the current cache by making a small change within the C#. The outputs **must** be set on both C# projects, not just one. – Craigory Coppola Jan 24 '23 at 19:31
  • See original post. Still getting a not found error, but it is picking up the /intermediates/ directory now. I'm curious about the /ref/ part of the path or should it pick up anything below `obj`? – Jason Jan 24 '23 at 20:12
  • Update: I was able to get this working, see original post for update – Jason Jan 25 '23 at 15:57