AvaloniaUI / AvaloniaVSCode

Visual Studio Code Extension for Avalonia UI
https://marketplace.visualstudio.com/items?itemName=AvaloniaTeam.vscode-avalonia
MIT License
103 stars 16 forks source link

Method '[MSBuild]::SubstringByAsciiChars' not found when project name is long #137

Open tmp64 opened 1 week ago

tmp64 commented 1 week ago

Describe the bug

If project name (including .csproj) is longer than 17 chars, SolutionParser fails with this error:

dotnet "c:\Users\user\.vscode\extensions\avaloniateam.vscode-avalonia-0.0.31\solutionParserTool\SolutionParser.dll" "c:\redacted\avalonia-learn\avalonia-learn.sln"

Error parsing project GetStartedApp: Invalid static method invocation syntax: "[MSBuild]::SubstringByAsciiChars($(MSBuildProjectFile), 0, 8)". Method '[MSBuild]::SubstringByAsciiChars' 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:\Program Files\dotnet\sdk\8.0.403\Microsoft.Common.CurrentVersion.targets

Relevant part of Microsoft.Common.CurrentVersion.targets:

  <PropertyGroup Condition="'$(MSBuildCopyMarkerName)' == ''">
    <MSBuildCopyMarkerName>$(MSBuildProjectFile)</MSBuildCopyMarkerName>
    <!-- For a long MSBuildProjectFile let's shorten this to 17 chars - using the first 8 codepoints of the filename and a filename hash. -->
    <MSBuildCopyMarkerName Condition="'$(MSBuildCopyMarkerName.Length)' &gt; '17'">$([MSBuild]::SubstringByAsciiChars($(MSBuildProjectFile), 0, 8)).$([MSBuild]::StableStringHash($(MSBuildProjectFile)).ToString("X8"))</MSBuildCopyMarkerName>
    <MSBuildCopyMarkerName>$(MSBuildCopyMarkerName).Up2Date</MSBuildCopyMarkerName>
  </PropertyGroup>

To Reproduce

  1. dotnet new install Avalonia.Templates
  2. dotnet new avalonia.mvvm -o GetStartedApp
  3. dotnet new sln
  4. dotnet sln add GetStartedApp
  5. Downgrade Avalonia to 11.0.2 and run dotnet restore
  6. Try to open the previewer and get "Previewer is not available. Build the project first."

Avalonia for VS Code

v0.0.31

Avalonia version

11.0.2

VS Code version

v1.95.1

Relevant log output

2024-11-02 11:35:24.720 [info] [Info  - 11:35:24 AM] AvaloniaLanguageServer.Handlers.TextDocumentSyncHandler: ** DidOpenText: file:///c:/redacted/avalonia-learn/GetStartedApp/Views/MainWindow.axaml | Uri='file:///c:/redacted/avalonia-learn/GetStartedApp/Views/MainWindow.axaml'
2024-11-02 11:35:25.302 [info] Command avalonia.previewProcess, file:///c%3A/redacted/avalonia-learn/GetStartedApp/Views/MainWindow.axaml
2024-11-02 11:35:29.358 [info] [EXT - INFO] Solution data path path: C:\Users\user\AppData\Local\Temp\avalonia-learn.sln.json
2024-11-02 11:35:29.434 [info] parser process args: C:\WINDOWS\system32\cmd.exe,/d,/s,/c,"dotnet "c:\Users\user\.vscode\extensions\avaloniateam.vscode-avalonia-0.0.31\solutionParserTool\SolutionParser.dll" "c:\redacted\avalonia-learn\avalonia-learn.sln""


### Additional context

_No response_
tmp64 commented 1 week ago

Relevant issue in SolutionParser: https://github.com/prashantvc/SolutionParser/issues/3

tmp64 commented 1 week ago

Workaround:

  1. Clone this commit by @trampster
  2. Build the cloned project
  3. Replace C:\Users\user\.vscode\extensions\avaloniateam.vscode-avalonia-0.0.31\solutionParserTool with the custom-built version