Skip to content

Dependency Graph not finding dependencies on class libraries when using MacOS #43

@photomoose

Description

@photomoose

Describe the bug
When using MacOS, the nx dependency graph does not show dependencies on class libraries from apps.

To Reproduce
Steps to reproduce the behavior:

  1. Create workspace
  2. Create console application (nx generate @nx-dotnet/core:app Demo.App)
  3. Create class library (nx generate @nx-dotnet/core:lib Demo.Lib)
  4. Using an IDE, create a class in Demo.Lib and consume it in Demo.App - ensure the IDE adds a project reference from Demo.App to Demo.Lib.
  5. Look at the dependency graph (nx dep-graph)

Expected behavior
The dependency graph should show a dependency on Demo.Lib from Demo.App.

Environment:

  • OS: MacOS
  • DotNet SDK: 5.0.100

Additional context
After some investigation, this problem appears to be caused by the fact that the DotNet CLI writes project reference paths into the *.csproj files using backslashes, for example:

  <ItemGroup>
    <ProjectReference Include="..\..\libs\demo.lib\DemoLib.csproj" />
  </ItemGroup>

If you manually edit the *.csproj file and convert the backslashes to forward slashes, then the dependency graph works as expected:

  <ItemGroup>
    <ProjectReference Include="../../libs/demo.lib/DemoLib.csproj" />
  </ItemGroup>

Strangely, if you create a unit test project for the app when prompted by nx, then the dependency from the test project to the app works fine despite the use of backslashes - maybe this works because it doesn't have to go up a folder to the libs folder?:

  <ItemGroup>
    <ProjectReference Include="..\demo.app\DemoApp.csproj" />
  </ItemGroup>

It looks like the DotNet CLI creates project references with backslashes; I wonder whether there's an issue with how resolve is calculating the paths here: https://github.com/nx-dotnet/nx-dotnet/blob/master/packages/utils/src/lib/utility-functions/workspace.ts#L60

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions