CommunityToolkit / CommunityToolkit/dotnet

Build errors when using CommunityToolkit.MVVM with Visual Studio extensions

Open
#889 1 comment 1 reaction 0 assignees View on GitHub
bug :bug:
Dominant language
C#
Stars
3.8k
Forks
400
PR merge metrics
No merged PRs in 30d

Description

### 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:

```cs
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][1]][1]

Also, source generator appears to work:

[![enter image description here][2]][2]

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

[![enter image description here][3]][3]

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?

[1]: https://i.sstatic.net/MBzU6OIpl.png
[2]: https://i.sstatic.net/M9oY3HpB.png
[3]: https://i.sstatic.net/DurdWT4E.png

### Regression

_No response_

### Steps to reproduce

```text
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

- [ ] CommunityToolkit.Common
- [ ] CommunityToolkit.Diagnostics
- [ ] CommunityToolkit.HighPerformance
- [X] CommunityToolkit.Mvvm (aka MVVM Toolkit)

### 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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.