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

Can't work in WinUI 3 project #59

Closed
huoyaoyuan opened this issue Jan 23, 2021 · 17 comments · Fixed by #128
Closed

Can't work in WinUI 3 project #59

huoyaoyuan opened this issue Jan 23, 2021 · 17 comments · Fixed by #128

Comments

@huoyaoyuan
Copy link

Start from WinUI 3 Preview 3 template project

Add package reference to Microsoft.Windows.CsWin32, with GetActiveWindow in NativeMethods.txt
Make a call to the method anywhere.

The IDE can correctly analysis all the occurrence and references of the method. However, when building the project, the command line output shows error CS0234: No member 'Windows' in namespace 'Microsoft'.

I think this is dotnet/roslyn#46420 , in another way.

@AArnott
Copy link
Member

AArnott commented Jan 23, 2021

I am not familiar with WinUI 3. But the symptoms are very similar to #7. Can you try the workaround documented there to see if it helps? Otherwise, we may need to move your bug to the WinUI team.

@huoyaoyuan
Copy link
Author

No, the workaround for #7 doesn't work here.

Seems that WinUI invokes legacy roslyn somehow.

@AArnott
Copy link
Member

AArnott commented Jan 24, 2021

@huoyaoyuan Where can I get this WinUI project template you're talking about so I can test it? Any idea where we can file issues against it?

@huoyaoyuan
Copy link
Author

@AArnott

https://github.com/microsoft/microsoft-ui-xaml
https://aka.ms/winui3/preview3-download

I can open issue myself there. They have been incompatible with several compiling stuff like dotnet build, <Nullable>enable</Nullable>.

If you have internal contacts, you may ask them about their interaction with roslyn and msbuild team. Thanks.

@dotMorten
Copy link

dotMorten commented Jan 26, 2021

I'm successfully using this with WinUI3. I've used this to have my WinUI3 app generate a tray icon, and clicking the tray icon will bring the WinUI3 window to the top.
Are you targeting Win32 or UWP?

@huoyaoyuan
Copy link
Author

I'm targeting Win32.

@dotMorten
Copy link

OK this is odd. Just created a new project and hit the same thing while compiling:

image

@dotMorten
Copy link

Investigating some more: The reason it worked for me was I was building a class library. But the moment I add XAML to that class library, this error occurs.

@huoyaoyuan
Copy link
Author

Yes. The #nullable issue occurs too when I add XAML. So I suspect they have the same root cause.

@dotMorten
Copy link

Seems like the XamlPrecompile step isn't including the generated files, and thus fails:
image

@huoyaoyuan
Copy link
Author

OK. So if XamlPrecompile invokes csc with custom command line and may not respect csproj, it's reasonable to report warning for no <Nullable>enable</Nullable>.

@dotMorten
Copy link

Seems duplicate to this: dotnet/roslyn#46300

@Sergio0694
Copy link
Member

Not sure if this has already been mentioned, but it seems this is not specific to WinUI 3 - I get the same exact error when trying to use a source generator that interacts with a XAML-related file in any way on vanilla UWP (SDK 19041) as well 🤔

@dotMorten
Copy link

@Sergio0694 Yes agreed. Not specific to this. It should probably be moved to the WinUI repo

@AArnott
Copy link
Member

AArnott commented Jan 29, 2021

Some investigations led to dotnet/msbuild#6096, which may fix the WinUI problem.

@dotMorten
Copy link

dotMorten commented Jan 29, 2021

@AArnott That helps some.
As mentioned in email "offline", the code generator need to prefix usings with global:: or it'll clash with WinUI. (props to @chsienki for discovering this)

AArnott added a commit that referenced this issue Jan 30, 2021
This addresses one problem with WinUI 3 projects consuming the generated source, as tracked by #59.
AArnott added a commit that referenced this issue Feb 18, 2021
AArnott added a commit that referenced this issue Feb 18, 2021
@dotMorten
Copy link

Just confirming that 0.1.370-beta works great with WinUI 3. Thank you!

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

Successfully merging a pull request may close this issue.

4 participants