CsWin32: "'Win32' does not exist in the namespace 'Windows'" when attempting to create AppX package
Actual behavior
Hi all! I’m currently attempting to create an AppX package for my app. I’ve created a packaging project in Visual Studio to include two projects in it, one of which is using CsWin32. I’m able to build them both fine and able to run them in the debugger without errors, but when I try to create an App package through my packaging project, I get these errors which I assume are related to CsWin32.
Wondering if this has been seen before, and if so what am I missing in perhaps my manifest or some csproj configuration?

Expected behavior
I haven’t hit these errors when building the project on its own and F5 debugging. I didn’t expect it to appear when attempting to create an AppX package with the project in it.
Repro steps
NativeMethods.txtcontent:
GetForegroundWindow
GetWindowThreadProcessId
SetWinEventHook
EVENT_SYSTEM_FOREGROUND
WINEVENT_OUTOFCONTEXT
- Any of your own code that should be shared? Happy to share any extra code as needed!
Context
- CsWin32 version: 0.1.647-beta
- Win32Metadata version (if explicitly set by project): unsure where to find that
- Target Framework: net6.0-windows10.0.22000.0
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 7
- Comments: 40 (16 by maintainers)
Workaround for folks dealing with multiple architectures:
Right-click the application project, click Publish, and create a folder publishing profile for each architecture. (You can also just create the .pubxml files manually.) Here’s what one should look like:
In Solution Explorer, select the packaging project. It will appear in the editor automatically. Associate the project(s) with all available publishing profiles:
The Project > Publish > Create App Packages wizard should now work correctly for any architecture that also has an associated publish profile. (Make sure you select the right targets and configurations!)
@AArnott here is a feedback link I created https://aka.ms/AAuybu5
Ok, I have a repro now, by adding an app packaging project to the solution: WpfApp2.zip
@AArnott here is the Visual Studio Feedback item.
https://developercommunity.visualstudio.com/t/CsWin32-causes-self-contained-packages-t/10867197?port=1025&fsid=30caf5d6-51ff-4d07-a5a1-f8cfb9d9b2d0
I can reproduce this with
SelfContained, unclear how to fix this one. What a mess, sigh! @AArnott Anyone left over there that can help with this?@AArnott I tried your sample project and repro’d the issue. However, I found that if I set the publish profile in the wapproj project reference I no longer get the error.
Thanks for understanding. And I’m sorry it’s taking me so long to get to this. FWIW it is still on my short list of things to get to. TBH it’s not likely to happen this week. I’m hopeful that I’ll have time next week.