Skip to content
This repository was archived by the owner on Sep 13, 2022. It is now read-only.
This repository was archived by the owner on Sep 13, 2022. It is now read-only.

[Question] Using UWP APIs from .NET Standard #786

@Neme12

Description

@Neme12

I have a PCL targeting .NET Framework 4.6 & UWP 10.0.10240 that I'm trying to convert to .NET Standard. It is actually used to share code that uses some UWP APIs that are available on desktop as well. I currently have these references in the project file:

<Reference Include="System.Runtime.WindowsRuntime">
  <HintPath>$(MSBuildProgramFiles32)\Reference Assemblies\Microsoft\Framework\.NETCore\v4.5\System.Runtime.WindowsRuntime.dll</HintPath>
</Reference>
<Reference Include="Windows">
  <HintPath>$(MSBuildProgramFiles32)\Windows Kits\10\UnionMetadata\Windows.winmd</HintPath>
</Reference>

Based on the target frameworks, I figured that my desired version of .NET Standard would be 1.3. However I'm getting compilation errors about missing mscorlib whenever I use any of the UWP APIs.

This is the new csproj:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netstandard1.3</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="System.Runtime.WindowsRuntime">
      <HintPath>$(MSBuildProgramFiles32)\Reference Assemblies\Microsoft\Framework\.NETCore\v4.5\System.Runtime.WindowsRuntime.dll</HintPath>
    </Reference>
    <Reference Include="Windows">
      <HintPath>$(MSBuildProgramFiles32)\Windows Kits\10\UnionMetadata\Windows.winmd</HintPath>
    </Reference>
  </ItemGroup>
</Project>

and a small example:

using Windows.Storage;

class C
{
    void M()
    {
        var folder = KnownFolders.PicturesLibrary; // error CS0012: The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
    }
}

I noticed that if I target netstandard2.0 instead, the compilation succeeds. But since I'm trying to target all versions of UWP, I can't afford that. Is it impossible to use these APIs from 1.3? Are PCLs the only option? Thank you (Sorry if this is not the appropriate repo)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions