nx-dotnet: [BUG] Visual Studio cannot open projects due to "Invalid static method invocation syntax" errors

Describe the bug I get errors when I try to open a dotnet project with Visual Studio 2022 community edition that uses the Directory.Build.props and Directory.Build.props files generated by nx-dotnet.

To Reproduce Steps to reproduce the behavior:

  1. Generate a nx-dotnet app with a sln.
  2. Open the sln in Visual Studio 2022 community edition.
  3. Observe that the project(s) are not actually loaded.
  4. Right click on the project that failed to load and click on “Reload Project”
  5. Observe error in popup dialog and in build output window.
---------------------------
Microsoft Visual Studio
---------------------------
Invalid static method invocation syntax: "[System.IO.Path]::GetRelativePath($(RepoRoot), $(MSBuildProjectDirectory))". Method 'System.IO.Path.GetRelativePath' not found. Static method invocation should be of the form: $([FullTypeName]::Method()), e.g. $([System.IO.Path]::Combine(`a`, `b`)). Check that all parameters are defined, are of the correct type, and are specified in the right order.  C:\Repos\MyProject\Directory.Build.props
---------------------------
OK   
---------------------------

Environment:

  • OS: Windows 11
  • IDE: Visual Studio 2022 community edition

Possible solution

I found the relevant documentation and it says any function in the System.IO.Path class should be invokable from these “property functions.” So, it should work. It doesn’t work on my box. There is another option that does work on my box and that’s [MSBuild]::MakeRelative, which looks to be a drop-in replacement for [System.IO.Path]::GetRelativePath in this context.

This is the change I’ve made on my projects. I’m happy to submit a pull request if that helps.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 19 (16 by maintainers)

Commits related to this issue

Most upvoted comments

Just replace [System.IO.Path]::GetRelativePath with [MSBuild]::MakeRelative, problem solved!

You sir just made my day… just stumbling on your reply when I needed it /salute

This works btw 😉

Just replace [System.IO.Path]::GetRelativePath with [MSBuild]::MakeRelative, problem solved!

Thanks @jgbright, but being honest, I only now noticed you mentioned it in your original issue as a possible solution! 😁

This is a trick I’ve used some times in the past when I was still doing Windows Development (though I can’t say I miss those days that much, tbh!)

There’s a leftover issue on windows caught by our smoke tests, but its unrelated to this PR. Pushing a fix now.

@jgbright I try to be receptive to PRs in particular, as I don’t have a ton of time to spend working on the plugin, unfortunately, and any contributions help immensely. In this particular case, I didn’t ask for a PR at first as I prefer the System.IO.Path implementation, but I had a hard time tracking down what was causing it actually to break. There’s a weird number of systems interacting here, and it’s hard to pin a version causing the issue.

In any case, the MSBuild namespaced method appears to be working properly, so we will continue with it for now.