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

Project using CsWin32 doesn't compile using msbuild because System.Memory is missing #875

Closed
SimonWeinbergerEnscape opened this issue Mar 7, 2023 · 6 comments · Fixed by #876
Labels
bug Something isn't working

Comments

@SimonWeinbergerEnscape
Copy link

Actual behavior

I'm trying to use CsWin32 source generators in our projects. It works when compiling in VisualStudio and works on our CI running "dotnet build", but doesn't run on our CI running "msbuild".

##[warning]CSC(0,0): Warning CS8785: Generator 'SourceGenerator' failed to generate source. It will not contribute to the output and compilation errors may occur as a result. Exception was of type 'FileNotFoundException' with message 'Could not load file or assembly 'System.Memory, Version=4.0.1.2, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system cannot find the file specified.'

Expected behavior

Compiling with "msbuild" does work.

Repro steps

  1. Create a sln with a csproj which references CsWin32.
  2. Build using MSBuild

I'm using Azure DevOps Server 2020 Update 1.1 with this step in a yaml pipeline, not sure what exactly happens in the background.

  - task: VSBuild-sxs@1
    inputs:
      solution: MySolution.sln
      maximumCpuCount: true
      vsVersion: 17.0
      platform: Any CPU
      configuration: Debug
      msbuildArchitecture: x64

However, the build log indicates it's "msbuild MySolution.sln" with a bunch of extra options in the end that are probably just relevant for the CI.

My own analysis

It looks like this an a general shortcoming of source generators, which must provide all their transitive dependencies. I have found this similar issue: dotnet/roslyn#52017

Probably the CsWin32 nuget package needs to have all it's transitive dependencies in the analyzers/cs folder.

Maybe this is a duplicate of #560, but I'm not entirely sure.

Context

  • CsWin32 version: 0.2.188-beta
  • Target Frameworks: net452;netcoreapp3.1;net6.0
  • LangVersion: 9.0
@SimonWeinbergerEnscape SimonWeinbergerEnscape added the bug Something isn't working label Mar 7, 2023
@AArnott
Copy link
Member

AArnott commented Mar 7, 2023

Some history is in #836. What version of VS is installed on your agent?

@Dimension4
Copy link

Hey, I work at the same company. We use VS Pro 17.2.6 on our agents.

@AArnott
Copy link
Member

AArnott commented Mar 8, 2023

Could you look for this file: "C:\Program Files\Microsoft Visual Studio\2022\MSBuild\Current\Bin\Roslyn\System.Memory.dll" and tell me what the assembly version is? (the path may need slight adjustment for your machine).

@Dimension4
Copy link

Dimension4 commented Mar 8, 2023

Here you go:
image

If I load the file via reflection I get:

System.Memory, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51

@AArnott
Copy link
Member

AArnott commented Mar 8, 2023

Ok, great. That 4.0.1.1 version is what I needed, and explains why the source generator fails on your machines. Upgrading VS would resolve the issue for you. I don't know if that's an option.
I checked, and there's no reason we can't reference 4.0.1.1 in the source generator though, so we should be able to make your system work with the next update.

@Dimension4
Copy link

Thanks a lot for looking into it, that's great news! I will also check if we can just upgrade our CI to the latest VS version, shouldn't be too much of an issue.

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

Successfully merging a pull request may close this issue.

3 participants