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?

image

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

  1. NativeMethods.txt content:
GetForegroundWindow
GetWindowThreadProcessId
SetWinEventHook

EVENT_SYSTEM_FOREGROUND
WINEVENT_OUTOFCONTEXT
  1. 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)

Most upvoted comments

Workaround for folks dealing with multiple architectures:

  1. 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:

    <?xml version="1.0" encoding="utf-8"?>
    <Project>
      <PropertyGroup>
        <Configuration>Release</Configuration>
        <Platform>ARM64</Platform>
        <PublishDir>..\Build\Release\arm64\net8.0-windows10.0.19041.0\win-arm64\publish\</PublishDir>
        <PublishProtocol>FileSystem</PublishProtocol>
        <_TargetId>Folder</_TargetId>
      </PropertyGroup>
    </Project>
    
  2. In Solution Explorer, select the packaging project. It will appear in the editor automatically. Associate the project(s) with all available publishing profiles:

      <ItemGroup>
        <ProjectReference Include="..\Solution\Project.csproj">
    +      <PublishProfile Condition="'$(Configuration)|$(Platform)'=='Release|x86'">Properties\PublishProfiles\x86.pubxml</PublishProfile>
    +      <PublishProfile Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Properties\PublishProfiles\x64.pubxml</PublishProfile>
    +      <PublishProfile Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">Properties\PublishProfiles\Arm64.pubxml</PublishProfile>
        </ProjectReference>
      </ItemGroup>
    
  3. 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

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.

image

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.