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

Source Generation Debug Launch Profile can reference non-netstandard2.0 versions of a multi-targeted library. #1128

Open
otac0n opened this issue Nov 22, 2023 · 3 comments

Comments

@otac0n
Copy link

otac0n commented Nov 22, 2023

I am multi-targeting my templating library Weave and have had to workaround what appears to be a bug in the debug launch profile for source generators.

You can find a repro case here:
https://github.com/otac0n/Weave/tree/feature-source-generators c49ef389

This workaround is (currently) working for debugging:

image

However, I will also report that the behavior of the workaround is quite stange.
It is not enough to make that change on the filesystem and debug, or even to restart Visual Studio. I found that I actually had to interact with the Project Settings dialog:

image

This may be a clue, or it may be aggressive caching that is unrelated.

Visual Studio Details:

Microsoft Visual Studio Professional 2022
Version 17.8.1
VisualStudio.17.Release/17.8.1+34316.72
Microsoft .NET Framework
Version 4.8.09032

Installed Version: Professional

Visual C++ 2022   00476-80000-00000-AA468
Microsoft Visual C++ 2022

ADL Tools Service Provider   1.0
This package contains services used by Data Lake tools

ASA Service Provider   1.0

ASP.NET and Web Tools   17.8.352.38654
ASP.NET and Web Tools

Azure App Service Tools v3.0.0   17.8.352.38654
Azure App Service Tools v3.0.0

Azure Data Lake Tools for Visual Studio   2.6.5000.0
Microsoft Azure Data Lake Tools for Visual Studio

Azure Functions and Web Jobs Tools   17.8.352.38654
Azure Functions and Web Jobs Tools

Azure Stream Analytics Tools for Visual Studio   2.6.5000.0
Microsoft Azure Stream Analytics Tools for Visual Studio

C# Tools   4.8.0-7.23558.1+e091728607ca0fc9efca55ccfb3e59259c6b5a0a
C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Common Azure Tools   1.10
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

Extensibility Message Bus   1.4.39 (main@e8108eb)
Provides common messaging-based MEF services for loosely coupled Visual Studio extension components communication and integration.

Microsoft Azure Hive Query Language Service   2.6.5000.0
Language service for Hive query

Microsoft Azure Stream Analytics Language Service   2.6.5000.0
Language service for Azure Stream Analytics

Microsoft Azure Tools for Visual Studio   2.9
Support for Azure Cloud Services projects

Microsoft JVM Debugger   1.0
Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

Mono Debugging for Visual Studio   17.8.17 (957fbed)
Support for debugging Mono processes with Visual Studio.

NuGet Package Manager   6.8.0
NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/

Razor (ASP.NET Core)   17.8.3.2353105+f0a326f3e15b2370371693a76fd379635387c74d
Provides languages services for ASP.NET Core Razor.

SQL Server Data Tools   17.8.119.0
Microsoft SQL Server Data Tools

Test Adapter for Boost.Test   1.0
Enables Visual Studio's testing tools with unit tests written for Boost.Test.  The use terms and Third Party Notices are available in the extension installation directory.

Test Adapter for Google Test   1.0
Enables Visual Studio's testing tools with unit tests written for Google Test.  The use terms and Third Party Notices are available in the extension installation directory.

ToolWindowHostedEditor   1.0
Hosting json editor into a tool window

TypeScript Tools   17.0.20920.2001
TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools   4.8.0-7.23558.1+e091728607ca0fc9efca55ccfb3e59259c6b5a0a
Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual F# Tools   17.8.0-beta.23475.2+10f956e631a1efc0f7f5e49c626c494cd32b1f50
Microsoft Visual F# Tools

Visual Studio IntelliCode   2.2
AI-assisted development for Visual Studio.

VisualStudio.DeviceLog   1.0
Information about my package

VisualStudio.Mac   1.0
Mac Extension for Visual Studio

VSPackage Extension   1.0
VSPackage Visual Studio Extension Detailed Info

Xamarin   17.8.0.155 (d17-8@7042beb)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin Designer   17.8.3.6 (remotes/origin/d17-8@eccf46a291)
Visual Studio extension to enable Xamarin Designer tools in Visual Studio.

Xamarin.Android SDK   13.2.2.0 (d17-5/45b0e14)
Xamarin.Android Reference Assemblies and MSBuild support.
    Mono: d9a6e87
    Java.Interop: xamarin/java.interop/d17-5@149d70fe
    SQLite: xamarin/sqlite/3.40.1@68c69d8
    Xamarin.Android Tools: xamarin/xamarin-android-tools/d17-5@ca1552d
@sharwell
Copy link
Member

Note that the only debugging strategy I would recommend for source generators is writing a unit test with the source generator testing library and debugging the unit test.

@otac0n
Copy link
Author

otac0n commented Dec 2, 2023

@sharwell I am also seeing an issue when building a test project as you suggested.

Target CoreCompile:
2>  CompilerServer: server failed - server rejected the request due to analyzer / generator issues 'analyzer assembly 'C:\Users\otac0n\Projects\Weave\Weave\bin\Debug\net461\Weave.exe' has MVID 'aa714b17-ce2c-4978-913b-7efc5ff79beb' but loaded assembly 'C:\Users\otac0n\AppData\Local\Temp\VBCSCompiler\AnalyzerAssemblyLoader\bad8135ebc01479e82c10d3755f6f265\1\Weave.exe' has MVID '27c27310-b0ad-4715-a51c-efba8778c534'' - c4784ddc-e1b8-4469-9bcc-787c333778eb

I am multi-targeting, sure. But analyzers can only come from netstandard2.0. It makes no sense for this to be the analyzer assembly reference found (even though my test project is set to net461 at the moment.)

I think this is a bug.

@otac0n
Copy link
Author

otac0n commented Dec 2, 2023

Seems like this is about a half a workaround:

    <ProjectReference Include="..\Weave\Weave.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" SetTargetFramework="TargetFramework=netstandard2.0" />

I have to manually reference MSBuild files and etc. from my package project (which would be provided via NuGet normally), which feels like a medium-sized oversight as well.

  <PropertyGroup>
    <WeaveAssemblyPath>$(MSBuildThisFileDirectory)..\Weave\bin\$(Configuration)\net461\Weave.exe</WeaveAssemblyPath>
  </PropertyGroup>
  <Import Project="..\Weave\Weave.targets" />

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants