简体   繁体   中英

ASP.NET MVC Web Application on Windows 10 IOT Raspberry PI

I have been fighting with this for about a week and am out of ideas. What I am trying to do is get a default ASP.NET 5 application running on Windows 10 IOT on a Raspberry PI 2. Everything runs great on my local machine but no matter what I try, my end result is the same on the PI.

尝试在PI上运行web.cmd时收到错误

I am creating an ASP.NET web application by going to file new project => ASP.NET web application and selecting the pre-configured Web Application under ASP.NET 5 Templates (got the exact same error starting with a blank template as well). I then modified the project.json web command to listen on port 5000.

"web": "Microsoft.AspNet.Server.Kestrel --server.urls http://0.0.0.0:5000 "

I then removed the pre-publish scripts from the project.json. At this point I am able to run the debugger using the web debugging configuration and access the site from a browser by navigating to localhost:5000. Awesome!

.NET versions on my local machine are below (dnvm list)

我的DNVM配置

With this configuration I then ran the below command:

dnu publish --out C:\\publish\\WebApplication1 --no-source --runtime dnx-coreclr-win-arm.1.0.0-rc2-16595

Everything publishes with no errors or warnings. Again, all seems well (feeling good). I then move the files to the PI's Programs directory (“c:\\PROGRAMS”) and made sure port 5000 is open. Next, I navigate to the approot directory on the PI and run .\\cmd and get the error posted above. I tried several different daily builds hoping it was bug but obviously I am doing something wrong along the way. Any insight on this would be great! Thanks in advance for your time.

Below is my project.json.

{
  "userSecretsId": "aspnet5-WebApplication1-2d6e07ad-d9e8-40d7-8e21-68bb479b8112",
  "version": "1.0.0-*",
  "compilationOptions": {
    "emitEntryPoint": true
  },

  "dependencies": {
    "EntityFramework.Commands": "7.0.0-rc1-final",
    "EntityFramework.MicrosoftSqlServer": "7.0.0-rc1-final",
    "Microsoft.AspNet.Authentication.Cookies": "1.0.0-rc1-final",
    "Microsoft.AspNet.Diagnostics.Entity": "7.0.0-rc1-final",
    "Microsoft.AspNet.Identity.EntityFramework": "3.0.0-rc1-final",
    "Microsoft.AspNet.IISPlatformHandler": "1.0.0-rc1-final",
    "Microsoft.AspNet.Mvc": "6.0.0-rc1-final",
    "Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-rc1-final",
    "Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final",
    "Microsoft.AspNet.StaticFiles": "1.0.0-rc1-final",
    "Microsoft.AspNet.Tooling.Razor": "1.0.0-rc1-final",
    "Microsoft.Extensions.CodeGenerators.Mvc": "1.0.0-rc1-final",
    "Microsoft.Extensions.Configuration.FileProviderExtensions" : "1.0.0-rc1-final",
    "Microsoft.Extensions.Configuration.Json": "1.0.0-rc1-final",
    "Microsoft.Extensions.Configuration.UserSecrets": "1.0.0-rc1-final",
    "Microsoft.Extensions.Logging": "1.0.0-rc1-final",
    "Microsoft.Extensions.Logging.Console": "1.0.0-rc1-final",
    "Microsoft.Extensions.Logging.Debug": "1.0.0-rc1-final",
    "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0-rc1-final"
  },

  "commands": {
    "web": "Microsoft.AspNet.Server.Kestrel --server.urls http://0.0.0.0:5000",
    "ef": "EntityFramework.Commands"
  },

  "frameworks": {
    "dnx451": { },
    "dnxcore50": { }
  },

  "exclude": [
    "wwwroot",
    "node_modules"
  ],
  "publishExclude": [
    "**.user",
    "**.vspscc"
  ]
}

Below is my global.json.

{
    "projects": [ "src", "test" ],
    "sdk": { 
        "version":  "1.0.0-rc2-16595"
    }
}

If it is an issue with mixing rc1 packages with rc2, how do I update everything to rc2? Based on my understanding I can't get rc1 of the core-clr for ARM based processors because its still beta. I tried removing 1.0.0-rc1-update1 but when I create the MVC application, Visual Studio seems to reinstall it. I do agree that everything I have read points to the mixing of versions but I am unsure how to force everything to rc2 versions of the dnx.

I tried a similar thing. I wanted to have a REST API WebServer on my Raspberry Pi with Windows 10 IoT. Was not as easy as I thought.

First I tried it with Windows Universal and the Backround Application (IoT). But at least from MS side there is no support for a Webserver there. So I found the REST Webserver RESTUP from a project group which did exactly what I wanted (Nuget package is available) https://github.com/tomkuijsten/restup

After I realized that it is possible to run .NET Core applications on the Windows 10 IoT I got interested how to set up a ASP.NET Core WebAPI project.

Short: it is now possible to create a so called publish with the ASP.NET Core 2 Preview SKD ( https://blogs.msdn.microsoft.com/webdev/2017/05/10/aspnet-2-preview-1/ ) download and install the SDK on your development machine.

The main difference to .NET Core 1.x and ASP.NET Core 1.x is the ARM support (Raspberry Pi) which ships with (ASP).NET Core 2. Until now the tool support is still in development. You can try to do it with VS 2017 Preview (15.3). I just found the manuals on github .NET Core 2 and used the command line tools (dotnet restore, publish etc) to build and publish the package.

At first I got an libuv DLL not found error. This was because I used 'win8-arm' from a web manual as instead of 'win-arm'. Seems that libuv has no binding(?) for win8-arm. However if you set the runtime identifier to 'win-arm' it is working fine and you will find the livuv.dll in the publish folder.

I provide you with the nuget.config and the VS project file dependencies .csproj to build and publish your ASP.NET Core application and run it.

nuget.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
        <clear />
        <add key="AspNetVNext" value="https://dotnet.myget.org/F/aspnetcore-dev/api/v3/index.json" />
        <add key="dotnet-core" value="https://dotnet.myget.org/F/dotnet-core/api/v3/index.json" />
        <add key="NuGet.org" value="https://api.nuget.org/v3/index.json" />
  </packageSources>
</configuration>

The contents for your VS project file .csproj:

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

  <PropertyGroup>
   <OutputType>exe</OutputType> 
   <TargetFramework>netcoreapp2.0</TargetFramework> 
   <RuntimeFrameworkVersion>2.0.0-preview1-final</RuntimeFrameworkVersion>
   <RuntimeIdentifiers>win-arm;win7-x64</RuntimeIdentifiers>
  </PropertyGroup>

  <ItemGroup>
    <Folder Include="wwwroot\" />
  </ItemGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore" Version="2.0.0-preview1-final" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.0.0-preview1-final"  />
  </ItemGroup>

</Project>

Now open a PowerShell cmd window in your project folder and execute following commands:

dotnet restore

dotnet publish -r win-arm

You will find your package under .\\bin\\Debug\\netcoreapp2.0\\win-arm\\publish if you copy the content via fileshare to your Windows 10 IoT Raspberry Pi and open a PowerShell connection to your device and navigate to your folder and execute the exe. The webserver will then be created and can be accessed.

You may have to open your specified port in the Windows 10 IoT firewall. If you using http port 80 execute first:

netsh advfirewall firewall add rule name="Open 80" dir=in action=allow protocol=TCP localport=80
netsh advfirewall firewall add rule name="Open 80" dir=out action=allow protocol=TCP localport=80

If you want the webserver not be be quit after you close your PowerShell use the following PowerShell command to fork the process. You can delete the process later via the Webportal.

Start-Process -NoNewWindow .\{yourapp}.exe

Hope that helps someone...

This is not a supported App model on iot-core as far as I know. The iot-core supports Universal Windows Programs/Apps, not ASP.Net 5 (yet). This isn't to say that you can't run web applications on the RPi with iot-core, you'll just have to probably use node.js at the moment or use WebClient/API/messaging to the cloud and run your WebApp there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM