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

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

Open
tmp64 opened this issue Nov 2, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@tmp64
Copy link

tmp64 commented Nov 2, 2024

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 tmp64 added the bug Something isn't working label Nov 2, 2024
@tmp64
Copy link
Author

tmp64 commented Nov 2, 2024

Relevant issue in SolutionParser: prashantvc/SolutionParser#3

@tmp64
Copy link
Author

tmp64 commented Nov 2, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant