How to create NET461 WebApplication with NetCore project template?

Damir Dobric Posts

Next talks:

 

    

Follow me on Twitter: #ddobric



 

 

Archives

 

We have a WebApplication build on top of .NET Core Webproject template, which targets full .NET framework version instead of .NET Core. Some of you may ask why somebody would do that. The reason is simple. There are libraries out there, which currently runs on .NET Framework only. For example IotHub Service SDK.
Because of this, we had to fallback to .NET Framework.

Usually, you should be able to do this in VS property page:

image

Unfortinatelly, if your project is set to .NET framework, you will not be able to do this by using VS. In that case open project file .csproj and do following changes manually (se yellow lines).

<PropertyGroup>
  <OutputType>Exe</OutputType>
  <TargetFramework>net461</TargetFramework>
  <RuntimeIdentifier>win7-x64</RuntimeIdentifier>

  <PackageTargetFallback Condition=" '$(TargetFramework)' == 'netcoreapp1.0' ">$(PackageTargetFallback);dnxcore50</PackageTargetFallback>
  <PackageTargetFallback Condition=" '$(TargetFramework)' == 'net461' ">$(PackageTargetFallback)</PackageTargetFallback>
  <PreserveCompilationContext>true</PreserveCompilationContext>
</PropertyGroup>

After that you will most likely get following errors:

C:\Program Files\dotnet\sdk\1.0.0-preview4-004233\NuGet.targets(70,5): error : Package Microsoft.NETCore.App 1.0.1 is not compatible with net461 (.NETFramework,Version=v4.6.1). Package Microsoft.NETCore.App 1.0.1 supports: netcoreapp1.0 (.NETCoreApp,Version=v1.0) [C:\git\DaenetIotService\IoTService\src\IotService\IoTService.csproj]
C:\Program Files\dotnet\sdk\1.0.0-preview4-004233\NuGet.targets(70,5): error : One or more packages are incompatible with .NETFramework,Version=v4.6.1. [C:\git\DaenetIotService\IoTService\src\IotService\IoTService.csproj]
C:\Program Files\dotnet\sdk\1.0.0-preview4-004233\NuGet.targets(70,5): error : Package Microsoft.NETCore.App 1.0.1 is not compatible with net461 (.NETFramework,Version=v4.6.1) / win7-x64. Package Microsoft.NETCore.App 1.0.1 supports: netcoreapp1.0 (.NETCoreApp,Version=v1.0) [C:\git\DaenetIotService\IoTService\src\IotService\IoTService.csproj]
C:\Program Files\dotnet\sdk\1.0.0-preview4-004233\NuGet.targets(70,5): error : One or more packages are incompatible with .NETFramework,Version=v4.6.1 (win7-x64). [C:\git\DaenetIotService\IoTService\src\IotService\IoTService.csproj]

Please notice there NETCore.App package. This package is usually consisted part of .NET Core web application. You will have to remove it to avoid errors.

Navigate to ItemGroup (in .csproj) with package references, lookup Microsoft.NETCore.App *.* and remove it.
Following shows (as an example) how this group should look like.

<ItemGroup>
   <PackageReference Include="Microsoft.AspNetCore.Authentication" Version="1.1.0" />
   <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="1.1.0" />
   <PackageReference Include="Microsoft.AspNetCore.Diagnostics" Version="1.1.0" />
   <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.0.1" />
   <PackageReference Include="Microsoft.AspNetCore.Routing" Version="1.0.1" />
   <PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration" Version="1.0.0" />
   <PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="1.0.1" />
   <PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="1.0.0" />
   <PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="1.0.0" />
   <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="1.0.0" />
   <PackageReference Include="Microsoft.Extensions.Logging" Version="1.0.0" />
   <PackageReference Include="Microsoft.Extensions.Logging.Console" Version="1.0.0" />
   <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.0.0" />
   <PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="1.0.0" />
   <PackageReference Include="Swashbuckle" Version="6.0.0-beta902" />
</ItemGroup>


Posted Jan 17 2017, 07:24 AM by Damir Dobric

Add a Comment

(required)  
(optional)
(required)  
Remember Me?
developers.de is a .Net Community Blog powered by daenet GmbH.