Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
photomoose opened this issue May 18, 2021 · 12 comments · Fixed by #45 or #50
Closed

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

photomoose opened this issue May 18, 2021 · 12 comments · Fixed by #45 or #50

Comments

@photomoose
Copy link
Contributor

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

@photomoose photomoose added bug Something isn't working needs-triage This issue has yet to be looked over by a core team member labels May 18, 2021
@AgentEnder AgentEnder removed the needs-triage This issue has yet to be looked over by a core team member label May 18, 2021
@AgentEnder
Copy link
Member

Hey @photomoose! Thanks for this issue, excited to see people trying this out on non-windows machines as I am sure that is where the plugin should shine.

I think I know what causes this, will get a fix out soon.

AgentEnder added a commit that referenced this issue May 18, 2021
MacOS / Linux use different directory separators, and we relied on it being a forward slash.
fixes #43
github-actions bot pushed a commit that referenced this issue May 18, 2021
## [0.5.2](v0.5.1...v0.5.2) (2021-05-18)

### Bug Fixes

* **core:** dep-graph with various directory separators ([3beccb4](3beccb4)), closes [#43](#43)
@github-actions
Copy link
Contributor

🎉 This issue has been resolved in version 0.5.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

@AgentEnder
Copy link
Member

@photomoose Let me know if you are still having issues with this, I don't have a mac available for testing just yet.

@photomoose
Copy link
Contributor Author

@AgentEnder thanks for the quick fix, but unfortunately this didn't actually resolve the issue! I will take a look at it to see what's going on...

@AgentEnder AgentEnder reopened this May 19, 2021
@AgentEnder
Copy link
Member

Ah, drat. I'll see if I cannot get to the bottom of this later tonight.

@AgentEnder
Copy link
Member

I was able to reproduce this via WSL2, so I should be able to publish a fix more confidently.

AgentEnder added a commit that referenced this issue May 19, 2021
inconsistent directory separators between .net CLI caused path.resolve to behave weirdly.

fixes #43
github-actions bot pushed a commit that referenced this issue May 19, 2021
## [0.6.2](v0.6.1...v0.6.2) (2021-05-19)

### Bug Fixes

* **utils:** getDependantProjectsForNxProject should work on Unix ([96cbc33](96cbc33)), closes [#43](#43)
@github-actions
Copy link
Contributor

🎉 This issue has been resolved in version 0.6.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

@photomoose
Copy link
Contributor Author

@AgentEnder I can confirm this now works! Cheers.

@AgentEnder
Copy link
Member

Haha! Excellent. Thanks for the confirmation. Anything else bumpy on non-windows machines? I really want to keep mac / linux first class.

@photomoose
Copy link
Contributor Author

Not yet, I haven't really used it in anger yet, I'm still trying to get a feel how this might work with a .NET project / mono-repo...

Our .NET applications run inside K8s, so our build artifacts are Docker images, where the Dockerfile copies the .NET source code into the build container and compiles it into a final image - (which can be achieved by bringing in the nx-docker plugin and adding a docker target to workspace.json) - your dependency fix now ensures the Docker images are built when changes occur.

Building / running tests locally is typically done inside the IDE (i.e. Rider) so we don't really need to invoke nx as part of our local dev workflow. However, on the CI server, we run the tests inside Docker containers, running as part of a Docker Compose network with other dependencies (e.g. Elasticsearch etc. for integration tests) - this allows us to have no dependencies on the build agents, everything is inside containers. I'm trying to think how we might be able to do something with nx here...

I'm also trying to workout whether we should have a single build/deployment pipeline for the mono-repo as a whole or individual pipelines for each service in the mono-repo...

@AgentEnder
Copy link
Member

Understood. I do not have a ton of experience with docker + kubernetes (really painful on windows), so it has not been something I have heavily considered with the plugin.

Local development inside of an IDE like rider or Visual Studio is also something that is not a core focus for the plugin, but is something that we will strive to maintain. If a project is opened up in an IDE, nothing the user does there should break the nx plugin, and everything done there should be accounted for by the plugin in some way (e.g. the sync generator pulls in dependencies added by an ide instead of through the plugin generators).

The build/test/serve executors really shine when using vs-code or any other editor that does not have first class support for .NET. These also really shine in CI for cases w/o kubernetes, as the nx affected ... commands play with the dependency graph.

The end goal of this plugin is to enable cross-language repositories where you can house your typescript front ends + .NET back ends in the same repo, and use the same commands to build and test them. Another part of this is the hopeful integration of typescript class generation from the .NET OpenAPI / swagger docs (#4 )

@github-actions
Copy link
Contributor

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
2 participants