How to resolve ASP.NET.Core 2 Package restoration related warning and errors - asp.net

Whenever I start a .NET CORE 2 web App Project With Authentication (i.e. Individual Authentication) I get the following warning:
Package 'Microsoft.Composition 1.0.27' was restored using '.NETPortable,Version=v0.0,Profile=Profile259, .NETFramework,Version=v4.6.1' instead of the project target framework '.NETCoreApp,Version=v2.0'. This package may not be fully compatible with your project.
The issue doesn't stop here, I am trying to install Microsoft.AspNetCore.Authentication.Cookies and I get the following error:
Package restore failed. Rolling back package changes for project
I tried the following, ALL Failed!
Deleting Nuget.Config
I added <PropertyGroup> <PackageTargetFallback>$(PackageTargetFallback);dotnet</PackageTargetFallback> </PropertyGroup>
restore packages via dotnet restore
Clear Nuget Cache (from Tools>NuGet>Package Manager Settings)
How can I resolve this conflict?
this is my project file
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<MvcRazorCompileOnPublish>true</MvcRazorCompileOnPublish>
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback>
<UserSecretsId></UserSecretsId>
</PropertyGroup>
<PropertyGroup>
<PackageTargetFallback>$(PackageTargetFallback);dotnet</PackageTargetFallback>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0-preview2-final" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.0-preview2-final" PrivateAssets="All" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.0-preview2-final" PrivateAssets="All" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0-preview2-final" />
<DotNetCliToolReference Include="Microsoft.Extensions.SecretManager.Tools" Version="2.0.0-preview2-final" />
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0-preview2-final" />
</ItemGroup>
</Project>
and a snapshot from my screen

The dependency issues have been resolved by adding in .csproj and updating the following packages using NuGet,
<PackageReference Include="Microsoft.Composition" Version="1.0.27" ExcludeAssets="All" />
<PackageReference Include="System.Composition" Version="1.0.31" />
The .csproj is
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<MvcRazorCompileOnPublish>true</MvcRazorCompileOnPublish>
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback>
<UserSecretsId>***********</UserSecretsId>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0-preview2-final" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Cookies" Version="2.0.0-preview2-final" />
<PackageReference Include="Microsoft.AspNetCore.Identity" Version="2.0.0-preview2-final" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="2.0.0-preview2-final" />
<PackageReference Include="Microsoft.Composition" Version="1.0.31" ExcludeAssets="All" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="2.0.0-preview2-final" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.0.0-preview2-final" />
<PackageReference Include="System.Composition" Version="1.1.0-preview2-25405-01" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.0-preview2-final" PrivateAssets="All" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.0-preview2-final" PrivateAssets="All" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0-preview2-final" />
<DotNetCliToolReference Include="Microsoft.Extensions.SecretManager.Tools" Version="2.0.0-preview2-final" />
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0-preview2-final" />
</ItemGroup>
</Project>
Ref, Ref2

Related

.NET Core 2.1 Lambda function fails at runtime with FileNotFoundException for netstandard

I have a .NET Core 2.1 Lambda function. The csproj file looks like this:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<AWSProjectType>Lambda</AWSProjectType>
</PropertyGroup>
<ItemGroup>
<None Remove="chromium.br" />
</ItemGroup>
<ItemGroup>
<Content Include="chromium.br">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Amazon.Lambda.Core" Version="1.1.0" />
<PackageReference Include="amazon.lambda.logging.aspnetcore" Version="3.0.0" />
<PackageReference Include="amazon.lambda.serialization.json" Version="1.7.0" />
<PackageReference Include="microsoft.extensions.dependencyinjection" Version="3.1.3" />
<PackageReference Include="microsoft.extensions.logging" Version="3.1.3" />
<PackageReference Include="mono.posix.NETStandard" Version="1.0.0" />
<PackageReference Include="puppeteersharp" Version="2.0.2" />
</ItemGroup>
<ItemGroup>
<Reference Include="HeadlessChromium.Puppeteer.Lambda.Dotnet">
<HintPath>..\HeadlessChromium.Puppeteer.Lambda.Dotnet\HeadlessChromium.Puppeteer.Lambda.Dotnet.dll</HintPath>
</Reference>
</ItemGroup>
</Project>
The project compiles, but at runtime (i.e. in the Lambda environment), the application fails with the message:
Could not load file or assembly 'netstandard, Version=2.1.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified
How do I correct this?
I realised that the HeadlessChromium.Puppeteer.Lambda.Dotnet.dll I used was compiled against .NET Standard 2.1. Using the .NET Core 2.1 DLL instead solved the problem.

Asp.net core application deploy as exe

I create new application with asp.net core .net framework 4.6.1 not core2 .
When I build application or deploy its relased as .exe not dll.
below is web.config for publish folder :
<aspNetCore processPath=".\Projectxxx.Upload.exe"
stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout"/></system.webServer>
Is that mean the project is out process ?
Also if I get any error give me this message
HTTP Error 502.5 - ANCM Out-Of-Process Startup Failure
I want to make the project in process and run at windows platform only what can be do for that ?
Any help
this is my project file
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net461</TargetFramework>
<DebugType>full</DebugType>
<UserSecretsId>aspnet-Projectxxx.Upload-332B348E-4A41-4FF3-A789-DD081E38AE8A</UserSecretsId>
<TypeScriptToolsVersion>3.1</TypeScriptToolsVersion>
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Cookies" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.CookiePolicy" Version="2.2.8" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="2.2.1" />
<PackageReference Include="Microsoft.AspNetCore.HttpsPolicy" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.2.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.2.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.2.6" PrivateAssets="All" />
<PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="2.2.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.3" />
<PackageReference Include="Microsoft.Web.Administration" Version="11.1.0" />
</ItemGroup>
</Project>
"The in-process hosting model isn't supported for ASP.NET Core apps that target the .NET Framework."
Reference

Exclude wwwroot\dist from build asp.net dotnet core 2.0

I am trying to build asp.net dotnet core app vis CLI but I want to exclude wwwroot\dist\**\* from compilation.
In dist folder I have static file which need to be copied but not compiled. I tried by adding ItemGroup but cannot figure out.
Also I followed this document but there is something which I don't understand and probably diong wrong.
Here si sample configuration:
<ItemGroup>
<Compile Exclude="wwwroot\dist\**\*" />
</ItemGroup>
One of my error is:
error MSB4232: Items that are outside Target elements must have one
of the following operations: Include, Update, or Remove.
It should be like this:
<ItemGroup>
<Compile Remove="wwwroot\dist\**" />
<Content Remove="wwwroot\dist\**" />
<EmbeddedResource Remove="wwwroot\dist\**" />
<None Remove="wwwroot\dist\**" />
</ItemGroup>
But there could be something else in the game. Here is how "default" .net core 2 csproj should look like + "dist" folder ignore:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp1.1</TargetFramework>
<PackageTargetFallback>$(PackageTargetFallback);portable-net45+win8+wp8+wpa81;</PackageTargetFallback>
</PropertyGroup>
<ItemGroup>
<Compile Remove="wwwroot\dist\**" />
<Content Remove="wwwroot\dist\**" />
<EmbeddedResource Remove="wwwroot\dist\**" />
<None Remove="wwwroot\dist\**" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.3" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.1.2" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.2" />
<PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="1.1.2" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="1.0.1" />
</ItemGroup>
</Project>
If you want to have content of folder copied to output and still visible inside VS:
<ItemGroup>
<Compile Remove="wwwroot\dist\**" />
</ItemGroup>
You can also ensure that the items are never added to the project so you don't have to remove them. This can be a bit more performant if the directory is ver large. To add excludes to the default glob pattern, you'd add this to your project file:
<PropertyGroup>
<DefaultItemExcludes>$(DefaultItemExcludes);wwwroot\dist\**</DefaultItemExcludes>
</PropertyGroup>

Microsoft.AspNetCore.Hosting.Abstractions manifest definition does not match the assembly reference

When I run the Entitfy framework core command add-migration MyMigrationName in a class library I get the following error
Could not load file or assembly
'Microsoft.AspNetCore.Hosting.Abstractions, Version=1.1.1.0,
Culture=neutral, PublicKeyToken=adb9793829ddae60' or one of its
dependencies. The located assembly's manifest definition does not
match the assembly reference. (Exception from HRESULT: 0x80131040)
Funny thing there is no reference in my application to Abstractions.
Here is my csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup Label="Globals">
<SccProjectName>SAK</SccProjectName>
<SccProvider>SAK</SccProvider>
<SccAuxPath>SAK</SccAuxPath>
<SccLocalPath>SAK</SccLocalPath>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>net452</TargetFramework>
<AssemblyName>MyProjectName</AssemblyName>
<OutputType>Library</OutputType>
<PackageId>MyProjectName</PackageId>
<NetStandardImplicitPackageVersion>1.6.0</NetStandardImplicitPackageVersion>
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
<RootNamespace>MyProjectName</RootNamespace>
</PropertyGroup>
<ItemGroup>
<None Update="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<PackageReference Include="DocumentFormat.OpenXml" Version="2.5.0" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="1.1.2" />
<PackageReference Include="Microsoft.CSharp" Version="4.3.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="1.1.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="1.1.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="1.1.2" />
<PackageReference Include="System.Collections" Version="4.3.0" />
<PackageReference Include="System.Linq" Version="4.3.0" />
<PackageReference Include="System.Runtime" Version="4.3.0" />
<PackageReference Include="System.Threading" Version="4.3.0" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net452' ">
<Reference Include="System" />
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.0.0" />
</ItemGroup>
</Project>
In order to get NuGet to add the appropriate binding redirects to class library projects, you need to add the following to your *.csproj file.
<PropertyGroup>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
</PropertyGroup>

Nuget package restore failed Microsoft.Composition 1.0.27

I am using visual studio mac with latest .Net Core SDK on mac. In visual studio 2017 RC on windows everything is ok, but when i try to restore nuget packages on mac with visual studio mac it throws me error.
Package Microsoft.Composition 1.0.27 is not compatible with netcoreapp1.1 (.NETCoreApp,Version=v1.1). Package Microsoft.Composition 1.0.27 supports: portable-net45+win8+wp8+wpa81 (.NETPortable,Version=v0.0,Profile=Profile259)
One or more packages are incompatible with .NETCoreApp,Version=v1.1.
here is my *.csproj file
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<Description>Some</Description>
<Copyright>Some</Copyright>
<AssemblyTitle>Some</AssemblyTitle>
<TargetFramework>netcoreapp1.1</TargetFramework>
<PreserveCompilationContext>true</PreserveCompilationContext>
<AssemblyName>SharpCommerce</AssemblyName>
<OutputType>Exe</OutputType>
<PackageId>Some</PackageId>
<UserSecretsId>aspnet-SharpCommerce-ecd1a4f7-1de0-468a-8065-ab902c7aae9b</UserSecretsId>
<RuntimeFrameworkVersion>1.1.0</RuntimeFrameworkVersion>
<PackageTargetFallback>$(PackageTargetFallback);dotnet5.6;portable-net45+win8;portable-net45+win8+wp8+wpa81;</PackageTargetFallback>
<GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute>
<GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>
<GenerateAssemblyInformationalVersionAttribute>false</GenerateAssemblyInformationalVersionAttribute>
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
<PreBuildEvent></PreBuildEvent>
</PropertyGroup>
<ItemGroup>
<Content Update="wwwroot\**\*;**\*.cshtml;appsettings.json;web.config">
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authentication.Cookies" Version="1.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics" Version="1.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="1.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="1.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Routing" Version="1.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration" Version="1.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="1.1.0" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="1.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.Design" Version="1.1.0">
<PrivateAssets>All</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="1.0.0-msbuild3-final">
<PrivateAssets>All</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="1.1.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink.Loader" Version="14.1.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration" Version="1.1.0-preview4-final" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="1.1.0-msbuild3-final">
<PrivateAssets>All</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor" Version="1.1.1" />
<PackageReference Include="System.IO.FileSystem" Version="4.3.0" />
<PackageReference Include="Microsoft.Extensions.FileProviders.Physical" Version="1.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="1.1.0" />
<PackageReference Include="System.Reflection" Version="4.3.0" />
<PackageReference Include="System.Runtime.Loader" Version="4.3.0" />
<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="1.3.2" />
</ItemGroup>
<Target Name="PrepublishScript" BeforeTargets="PrepareForPublish">
<Exec Command="bower install" />
<Exec Command="dotnet bundle" />
</Target>
<ItemGroup>
<ProjectReference Include="..\..\Some.Core.Contracts\Some.Core.Contracts.csproj" />
<ProjectReference Include="..\..\Some.Core\Some.Core.csproj" />
</ItemGroup>
</Project>
If this package is a true PCL (not using bait&switch), you should be able to reference it using target fallback. Try to add
<PropertyGroup>
<PackageTargetFallback>dnxcore50;portable-net45+win8+wp8+wpa81</PackageTargetFallback>
</PropertyGroup>
to your project. There is no guarantee that it won't crash at runtime through.
Package Microsoft.Composition 1.0.27 supporting only .NET Framework 4.5, Windows 8, Windows Phone 8.1, Windows Phone Silverlight 8, Portable Class Libraries (PCL Profile 259) so its not compatible with .Net Core on Mac
Nuget information about package
https://www.nuget.org/packages/Microsoft.Composition/1.0.27
Answer from support:
Thanks for reporting this. Visual Studio for Mac in preview 4 is ignoring the PackageTargetFallback information. So the project.assets.json file does not have any imports which prevents NuGet from installing NuGet packages when they should be allowed. This bug should be fixed in the next release.

Resources