Skip to content

Can't (easily) build a Windows console app that accesses the clipboard #13624

@terrajobst

Description

@terrajobst

I was trying to build a console app that accesses the clipboard. The easiest thing I could think of was this:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net5.0-windows</TargetFramework>
    <UseWindowsForms>True</UseWindowsForms>
  </PropertyGroup>

</Project>

This compiles and runs, but the process isn't connected to the current console host, which causes no output to appear in the shell from which the console app was launched. I assume that's because the produced .exe uses the wrong subsystem.

I was able to work this around by not using UseWindowsForms and instead referencing the desktop framework:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net5.0-windows</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <FrameworkReference Include="Microsoft.WindowsDesktop.App" />
  </ItemGroup>

</Project>

It seems to me that UseWindowsForms somehow overwrites the OutputType property. Is this expected behavior?

/cc @dsplaisted @rainersigwald

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions