ionide / proj-info

Parse and evaluate MsBuild project files
MIT License
64 stars 37 forks source link

getProjectInfo with relative path does not work. #185

Open nojaf opened 1 year ago

nojaf commented 1 year ago

Describe the bug Hello, in https://github.com/fsprojects/FSharp.Formatting/issues/793 we discovered that ProjectLoader.getProjectInfo cannot be called with a relative project path.

Very concretely, it goes wrong in VisualTree.relativePathOf:

image

System.Uri doesn't accept the input: (dotnet fsi)

> System.Uri(".\\src\\Fantomas.Core\\");;
System.UriFormatException: Invalid URI: The format of the URI could not be determined.
   at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind, UriCreationOptions& creationOptions)
   at System.Uri..ctor(String uriString)
   at <StartupCode$FSI_0002>.$FSI_0002.main@() in C:\Users\nojaf\Projects\stdin:line 1
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr)

To Reproduce

Changing the test project to:

[<EntryPoint>]
let main argv =
    Environment.CurrentDirectory <- @"C:\Users\nojaf\Projects\fantomas"

    let _toolsPath =
        Init.init (IO.DirectoryInfo(@"C:\Users\nojaf\Projects\fantomas")) (Some(IO.FileInfo(@"C:\Program Files\dotnet\dotnet.exe")))
        //Init.init (IO.DirectoryInfo Environment.CurrentDirectory) None

    let info = ProjectLoader.getProjectInfo @".\src\Fantomas.Core\Fantomas.Core.fsproj" [] BinaryLogGeneration.Off [
              "TargetPath"
              "OutputType"
              "IsTestProject"
              "IsPackable"
              "RepositoryUrl"
              "UsesMarkdownComments"
              "FsDocsCollectionNameLink"
              "FsDocsLogoSource"
              "FsDocsNavbarPosition"
              "FsDocsTheme"
              "FsDocsLogoLink"
              "FsDocsLicenseLink"
              "FsDocsReleaseNotesLink"
              "FsDocsSourceFolder"
              "FsDocsSourceRepository"
              "FsDocsWarnOnMissingDocs"
              "RepositoryType"
              "RepositoryBranch"
              "PackageProjectUrl"
              "Authors"
              "GenerateDocumentationFile"
              //Removed because this is typically a multi-line string and dotnet-proj-info can't handle this
              //"Description"
              "PackageLicenseExpression"
              "PackageTags"
              "Copyright"
              "PackageVersion"
              "PackageIconUrl"
              //Removed because this is typically a multi-line string and dotnet-proj-info can't handle this
              //"PackageReleaseNotes"
              "RepositoryCommit"
              "TargetFrameworks"
              "RunArguments" ]
    ignore info
    0

reproduces the problem after updating the global json (in Fantomas repository) to

{
  "sdk": {
    "version": "6.0.405"
  }
}

Oh and you probably need to build Fantomas.Core as well.

Expected behaviour

Either we should get an exception in ProjectLoader.getProjectInfo those relative paths are not supported, or this should work.

nojaf commented 1 year ago

@TheAngryByrd what fix would you like to see for this?

TheAngryByrd commented 1 year ago

I guess you could try let fromUri = Uri(fromPath, UriKind.RelativeOrAbsolute) and see if that fixes the issue.