Skip to content

[BUG] Visual Studio cannot open projects due to "Invalid static method invocation syntax" errors #548

@jgbright

Description

@jgbright

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.

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