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

Results of the MVVM source generator are not always compiled #750

Open
1 of 4 tasks
mscholz5 opened this issue Aug 24, 2023 · 6 comments
Open
1 of 4 tasks

Results of the MVVM source generator are not always compiled #750

mscholz5 opened this issue Aug 24, 2023 · 6 comments
Labels
analyzer 👓 A new analyzer being implemented or updated bug 🐛 An unexpected issue that highlights incorrect behavior mvvm-toolkit 🧰 Issues/PRs for the MVVM Toolkit

Comments

@mscholz5
Copy link

mscholz5 commented Aug 24, 2023

Describe the bug

I have a solution consisting of multiple projects. Some are libraries and some are desktop applications based on WPF/XAML.
All projects use the code MVVM source generator.

The build of the desktop applications fail with CS0103 in the output window.
The build of the library projects works.

In both cases does IntelliSense not show any errors and I also find the generated code under "Analyse".

"CompilerGeneratedFilesOutputPath" and "EmitCompilerGeneratedFiles" also work only for the library projects, but not for the app projects.
Setting "IncludePackageReferencesDuringMarkupCompilation" to "true" does not solve anything.

Steps to reproduce

  1. Create a C# desktop application project within Visual Studio 17.7.2 based on WPF/XAML/.NET Framework 4.6.2.
  2. Add a nuget package MvvmToolkit v8.2.1
  3. Add the following code
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;

namespace example
{
    internal partial class MyClass : ObservableObject
    {
        [ObservableProperty]
        int _foo; // warning CS0169

        [RelayCommand]
        void Bar()
        {
            Foo = 1;  // error CS0103
        }
    }
}

Expected behavior

I expect, that the code generator is working also for the WPF/XAML projects.

IDE and version

VS 2022

IDE version

17.7.2

Nuget packages

  • CommunityToolkit.Common
  • CommunityToolkit.Diagnostics
  • CommunityToolkit.HighPerformance
  • CommunityToolkit.Mvvm (aka MVVM Toolkit)

Nuget package version(s)

8.2.1

Help us help you

I could support, but I do not know how to start. It looks as if the compiler discards the generated sources under unknown circumstances. Perhaps this is a topic for the Microsoft VS-Team.

@mscholz5 mscholz5 added the bug 🐛 An unexpected issue that highlights incorrect behavior label Aug 24, 2023
@ahmad-syafrudin
Copy link

having the same problem with .Net Framework 4.7.2 and CommunityToolkit.Mvvm 8.2.1
try to build and fail as shown below

image

image

@Sergio0694 Sergio0694 added mvvm-toolkit 🧰 Issues/PRs for the MVVM Toolkit analyzer 👓 A new analyzer being implemented or updated labels Aug 28, 2023
@Sergio0694
Copy link
Member

Duplicate of #643 or #158 I think?

Are you using packages.config, by any chance?
If not, is all your code in the same project as your app, and are you using a legacy-style .csproj file?

@mscholz5
Copy link
Author

mscholz5 commented Aug 28, 2023

#158 looks indeed like a duplicate, which I have not seen before.

I do not have a packages.config within the project. The MVVM Toolkit is added with a PackageReference-Tag.
The original csproj was created with the template "WPF App (.NET Framework)". Does this qualify as "legacy-style"?

I do not understand the answer of Chris Sienkiewicz. Is there way to upgrade the csproj style without changing the target framework?

@mscholz5
Copy link
Author

mscholz5 commented Aug 30, 2023

A workaround:

  • Download the ".NET Upgrade Assistent" and "Upgrade project features".
  • Check all project settings
  • If you use reference paths: Add these values manually into *.csproj.user and extend "AssemblySearchPaths". Example:
    <ReferencePath>MyPath1;MyPath2</ReferencePath>
    <AssemblySearchPaths>$(ReferencePath);$(AssemblySearchPaths)</AssemblySearchPaths>
  • If you use build events with macro usage:
    Most of macros will probably be empty. Remove and add the event script.
    It will be moved to the end of the csproj-file within a tag "target".
  • All comments within the csproj might be removed. Compare and restore such comments if needed.
  • In my case, the property "Prefer32Bit" was not set and caused exceptions on loading dependend libs. I changed the target to "Any CPU" and set "prefer 32 bit". After that I changed the target back to "x86". That seems to work for me.

@CodingOctocat
Copy link

VS17.7.3 + MvvmToolkit8.2.1 don't encounter this bug anymore!

@Yuval-pa
Copy link

VS17.7.3 + MvvmToolkit8.2.1 don't encounter this bug anymore!

using VS17.7.5 and MvvmToolKit8.2.1 to create a .Net Framework 4.8 WPF project.
I migrated to PackageReference, changed the language version to c# 8 and was able to reproduce this error.
After I read this issue I switched to MvvmToolKit8.0.0 and the problem remained unresolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer 👓 A new analyzer being implemented or updated bug 🐛 An unexpected issue that highlights incorrect behavior mvvm-toolkit 🧰 Issues/PRs for the MVVM Toolkit
Projects
None yet
Development

No branches or pull requests

5 participants