CommunityToolkit / dotnet

.NET Community Toolkit is a collection of helpers and APIs that work for all .NET developers and are agnostic of any specific UI platform. The toolkit is maintained and published by Microsoft, and part of the .NET Foundation.
https://docs.microsoft.com/dotnet/communitytoolkit/?WT.mc_id=dotnet-0000-bramin
Other
2.99k stars 294 forks source link

Build errors when using CommunityToolkit.MVVM with Visual Studio extensions #889

Open stigzler opened 3 months ago

stigzler commented 3 months ago

Describe the bug

I've asked around on SO and discord, but getting no joy. Forgive me if this is my misunderstanding. My SO post: I'm getting build errors despite the SourceGenerator apparently working correctly. Example code:

namespace VisGit.ViewModels
{
    public partial class MainViewModel: ObservableObject
    {     
        [ObservableProperty]
        string _exceptionMessageText = "Exception Text";

        public MainViewModel()
        {
            ExceptionMessageText = "Test Change";
        }
    }
}

Intellisense shows the public property ExceptionMessageText as being generated successfully:

enter image description here

Also, source generator appears to work:

enter image description here

However, I get the build error The name 'ExceptionMessageText' does not exist in the current context:

enter image description here

Full code: https://github.com/stigzler/VisGit/blob/1-setup-base-extension-environment/VisGit/ViewModels/MainViewModel.cs

Not sure what I'm dong wrong. I'm using .net Framework 4.8 (is that the issue?). Any ideas?

Regression

No response

Steps to reproduce

1. Create a new VSIX Project w/Tool Window project
2. Create any Class creating a new ObservableProperty via the Attribute

Expected behavior

priavte var is converted to Public property and usable in same class. Project also builds without error "The name '[x]' does not exist in the current context"

Screenshots

See OP

IDE and version

VS 2022

IDE version

4.8.09032

Nuget packages

Nuget package version(s)

8.2.2

Additional context

No response

Help us help you

Yes, I'd like to be assigned to work on this item

stigzler commented 3 months ago

I've narrowed it down some more. As getting more help on SO, have posted details there:

https://stackoverflow.com/questions/78619310/build-errors-when-using-communitytoolkit-mvvm-with-visual-studio-extensions

It feels like this really doesn't play nicely with VS Extensions. :(