Add resource to Xamarin.Forms NuGet - c#

I'm about to write a custom NuGet for Xamarin.Forms projects and want to include some resources (font awesome otfs) in the NuGet so the referencing projects can use them.
I've managed it to copy the files from the NuGet to the Android assets folder and mark them as assets file correctly.
However I'm not able to include them in iOS as resource files...
Did anyone know how to do that? Or how to include resources at all (with a NuGet).
Here is my code snippet from the csproj file (NuGet) that works for android but not for iOS:
<PropertyGroup Condition=" '$(Configuration)'=='Debug' ">
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>
<!-- If config is release create a package -->
<PropertyGroup Condition=" '$(Configuration)'=='Release' ">
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<!-- sourcelink: Include PDB in the built .nupkg -->
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
</PropertyGroup>
<ItemGroup>
<Folder Include="fonts" />
<FontFiles Include="fonts\*.otf" />
</ItemGroup>
<ItemGroup>
<None Remove="#(FontFiles)" />
</ItemGroup>
<ItemGroup Condition=" $(TargetFramework.StartsWith('xamarin.ios')) ">
<Compile Include="ios\**\*.ios.cs" />
<TfmSpecificPackageFile Include="#(FontFiles)" BuildAction="BundleResource" PackagePath="contentFiles\any\$(TargetFramework)\Resources\" />
</ItemGroup>
<ItemGroup Condition=" $(TargetFramework.StartsWith('monoandroid')) ">
<Compile Include="android\**\*.android.cs" />
<Folder Include="Assets\" />
<AndroidAsset Include="#(FontFiles)" Link="Assets\%(Filename)%(Extension)" />
</ItemGroup>

Related

Project reference in Nuget

I need to create a Nuget of project A which is dependent on project B (not a nuget project, local one).
I have added Project B as project dependency to project A and enabled property to generate package on build. It is creating nuget package file but not including all the files from project A.
I tried few things and google also but not finding much help.
I found one similar question Build NuGet Package automatically including referenced dependencies
but not working. I am able to create pkg but with few files copied over. while I can see all the files in debug folder. No idea on what basis Nuget is picking few files from project A.
Can anyone tell me what's wrong here.
<Project Sdk="Microsoft.NET.Sdk" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<TargetFramework>net462</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageVersion>1.0.0.0-alpha</PackageVersion>
<Platforms>x64</Platforms>
<TargetsForTfmSpecificBuildOutput>$(TargetsForTfmSpecificBuildOutput);CopyProjectReferencesToPackage</TargetsForTfmSpecificBuildOutput>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<PlatformTarget>x64</PlatformTarget>
<NoWarn></NoWarn>
<WarningsAsErrors />
<OutputPath>bin\Debug</OutputPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<PlatformTarget>x64</PlatformTarget>
<NoWarn></NoWarn>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<WarningsAsErrors />
<OutputPath>bin\Release</OutputPath>
</PropertyGroup>
<ItemGroup>
<Reference Include="System.Configuration" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="someProject.csproj">
<ReferenceOutputAssembly>true</ReferenceOutputAssembly>
<IncludeAssets>all</IncludeAssets>
</ProjectReference>
</ItemGroup>
<Target DependsOnTargets="ResolveReferences" Name="CopyProjectReferencesToPackage">
<ItemGroup>
<BuildOutputInPackage Include="#(ReferenceCopyLocalPaths->WithMetadataValue('ReferenceSourceTarget', 'ProjectReference'))"/>
</ItemGroup>
</Target>
</Project>

C# MSBuild not including the NuGet packages (works in Visual Studio 17)

I am using PackageReference in my .csproj file and my build works in Visual Studio (2017). I'm building with .net 4.5 I have looked at this:
(MSBuild not adding a /reference for nuget PackageReference when building with jenkins)
I was at first having the issue on our build server so I tried it locally on my computer. I do a restore and then the build (or rebuild). the error is:
(CoreCompile target) ->
Properties\AssemblyInfo.cs(25,12): error CS0246: The type or namespace name 'log4net' could not be found (are you missing a using directive or an assembly reference?)
And in my project I have
<ItemGroup>
<PackageReference Include="log4net">
<Version>2.0.12</Version>
</PackageReference>
Thanks in advance.
Update
I created a simple solution/project that just includes one Nuget Package. I also created it with the latest framework in case that had any bearing on the issue. Again, it builds in VS2017 but fails using MSBuild the .csproj file is
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{9A64612A-63A2-4CA5-8470-75DD978D7449}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>testNetwonNugetProject</RootNamespace>
<AssemblyName>testNetwonNugetProject</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json">
<Version>13.0.1</Version>
</PackageReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
I verified that on restore the files are added to the project obj folder as well as user/roaming/nuget and user/.nuget/packages. I get the same error message as above.

Create multi-target Xamarin.Forms NuGet package

I'm trying to build a single NuGet package that can be installed in Xamarin.Android, Xamarin.iOS, Xamarin.UWP and Xamarin.Forms (.NET Standard) projects. I can't use .NET Standard since I need to have a custom Activity for my Android project, custom AppDelegate for my iOS project, and a custom MainPage for my UWP project. In the initiators I want to use the ServiceCollection as DI provider.
In the docs they still mention the Portable Class Library (explicitly mentioned legacy, doesn't exist anymore in VS), or Manually Creating Packages (can't figure out what to do here), and then you also have websites mentioning the Xamarin.Forms Plugin, which also doesn't exist anymore.
I already made a solution with all 4 projects, but I can't figure out how I can create a single NuGet package for all 4 projects (all 3 target platforms).
Does anyone have an idea how we can build a multi-target NuGet package containing code for Android, iOS, and UWP, just like the Xamarin.Forms NuGet package?
I've also seen discussions like this: How does one create a project to create a Nuget package for Xamarin Forms supporting iOS, Android, and UWP?, but I'm not sure if this is still relevant, since the build.props and build.targets no longer exist in the MvvmCross repo.
On starting point is https://github.com/onovotny/MSBuildSdkExtras
A year ago, I made a sample (and collected some documentation and references), which might be inspiring for this subject: https://github.com/ZeProgFactory/MSBuildSdkExtrasTest
and https://github.com/ZeProgFactory/MediaPlayer is using it
And definitively, you should look at the repositories of James Montemagno's components at https://github.com/jamesmontemagno
With these references you should be able to start. But all of these had a mayor difference with your approach:
they are using one project (via MSBuildSdkExtras),
which is builded for all the platforms
and, finally, the binaries are assembled in one NuGet.
Perhaps you may take only this last step. Anyway, this approach is at least an option.
Hope this helps …
I've pushed a working version to https://github.com/MintPlayer/MintPlayer.MVVM
csproj-file
<Project Sdk="MSBuild.Sdk.Extras/2.0.41">
<!-- You must have the Android 8.0 SDK installed through the Android SDK manager -->
<PropertyGroup>
<AssemblyName>MintPlayer.MVVM</AssemblyName>
<RootNamespace>MintPlayer.MVVM</RootNamespace>
<TargetFrameworks>netstandard2.0;Xamarin.iOS10;MonoAndroid80;uap10.0.16299</TargetFrameworks>
<_WriteTelemetryProperties>false</_WriteTelemetryProperties>
<Authors>Pieterjan De Clippel</Authors>
<Company>MintPlayer</Company>
<Product>MintPlayer.MVVM</Product>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<Description>This package allows you to implement ViewModel Navigation and Dependency Injection in a Xamarin.Forms project</Description>
<Version>1.0.0</Version>
<Copyright />
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/MintPlayer/MintPlayer.MVVM</PackageProjectUrl>
<RepositoryUrl>https://github.com/MintPlayer/MintPlayer.MVVM</RepositoryUrl>
<PackageTags>Xamarin.Forms, Viewmodel navigation, Dependency Injection</PackageTags>
<PackageReleaseNotes>This package is still under construction</PackageReleaseNotes>
</PropertyGroup>
<ItemGroup>
<Compile Remove="Platforms\**\*.cs" />
<None Include="Platforms\**\*.cs" />
<None Include="Resources\*.cs" />
<Compile Remove="Resources\*.cs" />
</ItemGroup>
<ItemGroup Condition=" $(TargetFramework.StartsWith('uap')) ">
<Compile Include="Platforms\UAP\**\*.cs" />
<Compile Include="Platforms\Common\**\*.cs" />
</ItemGroup>
<ItemGroup Condition=" $(TargetFramework.StartsWith('netstandard')) ">
<Compile Include="Platforms\Common\**\*.cs" />
</ItemGroup>
<ItemGroup Condition=" $(TargetFramework.StartsWith('Xamarin.iOS')) ">
<Compile Include="Platforms\iOS\**\*.cs" />
<Compile Include="Platforms\Common\**\*.cs" />
</ItemGroup>
<ItemGroup Condition=" $(TargetFramework.StartsWith('MonoAndroid')) ">
<Compile Include="Platforms\Android\**\*.cs" />
<Compile Include="Platforms\Common\**\*.cs" />
<AndroidResource Include="Resources\**\*.xml" SubType="Designer" Generator="MSBuild:UpdateAndroidResources" />
<AndroidResource Include="Resources\**\*.axml" SubType="Designer" Generator="MSBuild:UpdateAndroidResources" />
</ItemGroup>
<ItemGroup>
<None Remove="Platforms\Common\MintPlayerMvvmExtensions.cs" />
<None Remove="Platforms\Common\NavigationService.cs" />
<None Remove="Platforms\Common\Platform.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="3.1.6" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.6" />
<!--<PackageReference Include="Xamarin.Forms" Version="4.5.0.495" />-->
<PackageReference Include="Xamarin.Forms" Version="3.1.0.697729" />
</ItemGroup>
</Project>
Directory.build.props
<Project>
<PropertyGroup>
<Company>MintPlayer</Company>
<Copyright>Copyright © MintPlayer</Copyright>
<RepositoryUrl>https://github.com/MintPlayer/MintPlayer.MVVM</RepositoryUrl>
<Authors>Pieterjan De Clippel</Authors>
<Owners>MintPlayer</Owners>
<PackageReleaseNotes />
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<RepositoryType>git</RepositoryType>
<Product>$(AssemblyName) ($(TargetFramework))</Product>
<NeutralLanguage>en</NeutralLanguage>
<LangVersion>latest</LangVersion>
<NoWarn>$(NoWarn);1591;1701;1702;1705;VSX1000;NU1603</NoWarn>
<GenerateDocumentationFile Condition=" '$(Configuration)' == 'Release' ">true</GenerateDocumentationFile>
<GeneratePackageOnBuild Condition=" '$(Configuration)' == 'Release' and '$(IsTestProject)' != 'true'">true</GeneratePackageOnBuild>
<Platform>AnyCPU</Platform>
<DebugType>portable</DebugType>
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<IsTestProject>$(MSBuildProjectName.Contains('UnitTests'))</IsTestProject>
</PropertyGroup>
</Project>
Directory.build.targets
<Project>
<PropertyGroup Condition="$(TargetFramework.StartsWith('netstandard'))">
<DefineConstants>$(DefineConstants);NETSTANDARD;PORTABLE</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="$(TargetFramework.StartsWith('Xamarin.iOS'))">
<DefineConstants>$(DefineConstants);MONO;UIKIT;COCOA;IOS</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="$(TargetFramework.StartsWith('MonoAndroid'))">
<DefineConstants>$(DefineConstants);MONO;ANDROID</DefineConstants>
<MonoAndroidResourcePrefix>Resources</MonoAndroidResourcePrefix>
<AndroidResgenClass>Resource</AndroidResgenClass>
<AndroidResgenFile>Resources\Resource.designer.cs</AndroidResgenFile>
</PropertyGroup>
</Project>
You must add the following to your .sln file
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{7004E39A-BAF2-4F2F-B505-CC3DEC393CB6}"
ProjectSection(SolutionItems) = preProject
Directory.build.props = Directory.build.props
Directory.build.targets = Directory.build.targets
EndProjectSection
EndProject

Deploy click-once application with Azure Devops?

I have an error when deploying my click-once project with Azure DevOps Pipeline. I don't see where is my error.
First, I can build and publish my click-once application manually from Visual Studio. I have no issue.
When I use Azure DevOps Pipeline to build and publish my click-once application I get an error:
[error]C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets(780,5):
Error : The OutputPath property is not set for project
'******.vbproj'. Please check to make sure that you have specified a
valid combination of Configuration and Platform for this project.
Configuration='release' Platform='any cpu'. You may be seeing this
message because you are trying to build a project without a solution
file, and have specified a non-default Configuration or Platform that
doesn't exist for this project.
The OutputPath property is not set for project. Well, I don't know. Let me give you my project file:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{****}</ProjectGuid>
<OutputType>WinExe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>****.*****4</RootNamespace>
<AssemblyName>****.*****4</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<WarningLevel>4</WarningLevel>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<IsWebBootstrapper>true</IsWebBootstrapper>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
<TargetFrameworkProfile />
<PublishFilePath>$(PublishDir)install*****4.html</PublishFilePath>
<PublishUrl>\\server15\c%24\inetpub\wwwroot\*****4Install %28Staging%29\</PublishUrl>
<Install>true</Install>
<InstallFrom>Web</InstallFrom>
<UpdateEnabled>true</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>true</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<InstallUrl>http://*****4install-staging.newsprintgroup.com/</InstallUrl>
<ProductName>***** Application</ProductName>
<PublisherName>NewsPrint Group</PublisherName>
<MinimumRequiredVersion>4.15.0.0</MinimumRequiredVersion>
<CreateWebPageOnPublish>true</CreateWebPageOnPublish>
<WebPage>install*****4.html</WebPage>
<ApplicationRevision>1</ApplicationRevision>
<ApplicationVersion>4.15.9.1</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<CreateDesktopShortcut>true</CreateDesktopShortcut>
<PublishWizardCompleted>true</PublishWizardCompleted>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<ManifestCertificateThumbprint>57DF31CB3510678332744572F14AD9BAAC60178E</ManifestCertificateThumbprint>
</PropertyGroup>
<PropertyGroup>
<ManifestKeyFile>****.*****4_1_TemporaryKey.pfx</ManifestKeyFile>
</PropertyGroup>
<PropertyGroup>
<GenerateManifests>true</GenerateManifests>
</PropertyGroup>
<PropertyGroup>
<SignManifests>false</SignManifests>
</PropertyGroup>
<ItemGroup>
(...)
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SlowCheetahTargets)" Condition="Exists('$(SlowCheetahTargets)')" Label="SlowCheetah" />
<Import Project="..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets" Condition="Exists('..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets'))" />
<Error Condition="!Exists('..\packages\SlowCheetah.2.5.48\build\SlowCheetah.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\SlowCheetah.2.5.48\build\SlowCheetah.targets'))" />
</Target>
<Import Project="..\packages\SlowCheetah.2.5.48\build\SlowCheetah.targets" Condition="Exists('..\packages\SlowCheetah.2.5.48\build\SlowCheetah.targets')" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
This error only relevant with your incorrect configuration about the Platform in the
task. It should caused by the value you specified to Platform could not be recognized by the task. Without the Platform value, the server prompt the error message Please check to make sure that you have specified a valid combination of Configuration and Platform for this project.
Since what you used in the task is .*proj file instead of .sln file, to solve the error you are facing, here you need use AnyCPU rather than a normal value any cpu.
In this doc, it point out that corresponding to different file designation methods, you should use the different task configurations:

No references were found in the windows sdk (Windows 1903)

I want to create simple toast notification to action center in windows 10 from a WPF app using this article.
But I got problem on Step 2:
Right click on the project => Add => Reference... => Windows => Core
What I checked:
Windows 10 SDK Installation:
Same issue with a WPF project
And this is my csproj file:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{A5A389ED-4BBB-4EF4-A8A4-45DD3D0AF9AE}</ProjectGuid>
<OutputType>WinExe</OutputType>
<RootNamespace>WpfApp3</RootNamespace>
<AssemblyName>WpfApp3</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetPlatformVersion>10.0.10240.0</TargetPlatformVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<WarningLevel>4</WarningLevel>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xaml">
<RequiredTargetFramework>4.0</RequiredTargetFramework>
</Reference>
<Reference Include="WindowsBase" />
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
</ItemGroup>
<ItemGroup>
<ApplicationDefinition Include="App.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Page Include="MainWindow.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Compile Include="App.xaml.cs">
<DependentUpon>App.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="MainWindow.xaml.cs">
<DependentUpon>MainWindow.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
This error occurs after the update to Windows 1903, because Visual studio can not access C:\Windows\System32\WinMetadata
On updating to the May 2019 release of Windows 10 the directory C:\WINDOWS\SysWOW64\WinMetadata is removed and this is where Visual Studio is 2017 and 2019 is looking for all of the files.
There is 2 way to solve this:
1. Click Browse in reference manager and chose your reference from C:\WINDOWS\System32\WinMetadata.
2. Copy WinMetadata folder from C:\WINDOWS\System32\WinMetadata to C:\WINDOWS\SysWOW64\WinMetadata. and then re-open reference manager.
Looks like the parent bug is documented at https://developercommunity.visualstudio.com/content/problem/446490/visual-studio-cant-see-winmetadatadirectory-in-cwi.html
For me I clicked browse and used this path %windir%\Sysnative\WinMetadata and it worked for me. Windows 10 1903 \ VS 17
I've reproduced your issue. The node <TargetPlatformVersion> should be below the existing node <TargetFrameworkVersion> node.
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetPlatformVersion>10.0.10240.0</TargetPlatformVersion>
But there is the separate PropertyGroup with this node in your project file.
Visual Studio can not access the C:\Windows\System32\WinMetadata directory to load the windows SDK on Windows 1903.
So a downgrade from windows 1903 to 1803 solved this issue.
I have reported this problem on the visual studio developer community page.
Windows 1903:
Copy WinMetadata folder from (hidden folder) C:\WINDOWS\sysnative\WinMetadata to C:\WINDOWS\SysWOW64\WinMetadata.
Re-open reference manager.
​The folder %windir%\Sysnative\WinMetadata does not seem to exist on my Windows 1903 (OS Build 18362.900).
My workaround was to make a local copy of the required files in %windir%\System32\WinMetadata (e.g. under a lib folder in your solution) and reference them from there.
In my case, this is how I got a hold of the Windows.Data.winmd and Windows.UI.winmd files (couldn't find them on NuGet).

Categories