我在.Net核心上创建了一个asp.net核心,并计划在Windows服务器上发布它。我不想在服务器上安装任何东西,所以我希望应用程序是自包含的。
我选择了菜单" Build->发布MyApp"然后创建基于文件系统的方法。它在文件夹中生成以下文件,然后将其复制到服务器。但是,如何在没有安装.Net核心的服务器上运行它?
Name
----
refs
runtimes
appsettings.json
MyService.deps.json
MyService.dll
MyService.pdb
MyService.runtimeconfig.json
Microsoft.ApplicationInsights.AspNetCore.dll
Microsoft.ApplicationInsights.dll
Microsoft.AspNetCore.Antiforgery.dll
Microsoft.AspNetCore.Authorization.dll
Microsoft.AspNetCore.Cors.dll
Microsoft.AspNetCore.Cryptography.Internal.dll
Microsoft.AspNetCore.DataProtection.Abstractions.dll
Microsoft.AspNetCore.DataProtection.dll
Microsoft.AspNetCore.Diagnostics.Abstractions.dll
Microsoft.AspNetCore.Hosting.Abstractions.dll
Microsoft.AspNetCore.Hosting.dll
Microsoft.AspNetCore.Hosting.Server.Abstractions.dll
Microsoft.AspNetCore.Html.Abstractions.dll
Microsoft.AspNetCore.Http.Abstractions.dll
Microsoft.AspNetCore.Http.dll
Microsoft.AspNetCore.Http.Extensions.dll
Microsoft.AspNetCore.Http.Features.dll
Microsoft.AspNetCore.HttpOverrides.dll
Microsoft.AspNetCore.JsonPatch.dll
Microsoft.AspNetCore.Localization.dll
Microsoft.AspNetCore.Mvc.Abstractions.dll
Microsoft.AspNetCore.Mvc.ApiExplorer.dll
Microsoft.AspNetCore.Mvc.Core.dll
Microsoft.AspNetCore.Mvc.Cors.dll
Microsoft.AspNetCore.Mvc.DataAnnotations.dll
Microsoft.AspNetCore.Mvc.dll
Microsoft.AspNetCore.Mvc.Formatters.Json.dll
Microsoft.AspNetCore.Mvc.Localization.dll
Microsoft.AspNetCore.Mvc.Razor.dll
Microsoft.AspNetCore.Mvc.Razor.Host.dll
Microsoft.AspNetCore.Mvc.TagHelpers.dll
Microsoft.AspNetCore.Mvc.ViewFeatures.dll
Microsoft.AspNetCore.Razor.dll
Microsoft.AspNetCore.Razor.Runtime.dll
Microsoft.AspNetCore.Routing.Abstractions.dll
Microsoft.AspNetCore.Routing.dll
Microsoft.AspNetCore.Server.IISIntegration.dll
Microsoft.AspNetCore.Server.Kestrel.dll
Microsoft.AspNetCore.WebUtilities.dll
Microsoft.DotNet.InternalAbstractions.dll
Microsoft.EntityFrameworkCore.dll
Microsoft.EntityFrameworkCore.Relational.dll
Microsoft.EntityFrameworkCore.SqlServer.dll
Microsoft.Extensions.Caching.Abstractions.dll
Microsoft.Extensions.Caching.Memory.dll
Microsoft.Extensions.Configuration.Abstractions.dll
Microsoft.Extensions.Configuration.Binder.dll
Microsoft.Extensions.Configuration.dll
Microsoft.Extensions.Configuration.EnvironmentVariables.dll
Microsoft.Extensions.Configuration.FileExtensions.dll
Microsoft.Extensions.Configuration.Json.dll
Microsoft.Extensions.DependencyInjection.Abstractions.dll
Microsoft.Extensions.DependencyInjection.dll
Microsoft.Extensions.DependencyModel.dll
Microsoft.Extensions.DiagnosticAdapter.dll
Microsoft.Extensions.FileProviders.Abstractions.dll
Microsoft.Extensions.FileProviders.Composite.dll
Microsoft.Extensions.FileProviders.Physical.dll
Microsoft.Extensions.FileSystemGlobbing.dll
Microsoft.Extensions.Globalization.CultureInfoCache.dll
Microsoft.Extensions.Localization.Abstractions.dll
Microsoft.Extensions.Localization.dll
Microsoft.Extensions.Logging.Abstractions.dll
Microsoft.Extensions.Logging.Console.dll
Microsoft.Extensions.Logging.Debug.dll
Microsoft.Extensions.Logging.dll
Microsoft.Extensions.Logging.Filter.dll
Microsoft.Extensions.Logging.TraceSource.dll
Microsoft.Extensions.ObjectPool.dll
Microsoft.Extensions.Options.ConfigurationExtensions.dll
Microsoft.Extensions.Options.dll
Microsoft.Extensions.PlatformAbstractions.dll
Microsoft.Extensions.Primitives.dll
Microsoft.Extensions.WebEncoders.dll
Microsoft.Net.Http.Headers.dll
Newtonsoft.Json.dll
NLog.config
NLog.dll
NLog.Extensions.Logging.dll
Remotion.Linq.dll
System.Collections.NonGeneric.dll
System.Collections.Specialized.dll
System.ComponentModel.Primitives.dll
System.ComponentModel.TypeConverter.dll
System.Data.Common.dll
System.Diagnostics.Contracts.dll
System.Interactive.Async.dll
System.Net.WebSockets.dll
System.Runtime.Serialization.Primitives.dll
System.Text.Encodings.Web.dll
web.config
答案 0 :(得分:8)
.NET Core 1.0-wise解决方案:
1)打开project.json
文件并从type = "platform"
的依赖项中删除netcoreapp1.0
:
"frameworks": {
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
"version": "1.0.1"
}
}
}
}
2)指定要定位的运行时(.NET Core Runtime IDentifier catalog):
"runtimes": {
"win7-x64": {},
"osx.10.10-x64": {},
"ubuntu.14.04-x64": {}
}
3)在项目或解决方案文件夹级别的命令提示符中运行dotnet restore
。
4)建立:
dotnet build -r win7-x64
dotnet build -r osx.10.10-x64
dotnet build -r ubuntu.14.04-x64
5)发布:
dotnet publish -c release -r win7-x64
dotnet publish -c release -r osx.10.10-x64
dotnet publish -c release -r ubuntu.14.04-x64
文件夹%ProjectFolder%\bin\Release\netcoreapp1.0\
将是您发布的每个运行时的文件夹。
信用转到Scott Hanselman。
答案 1 :(得分:0)
请参阅您关联的说明中的第3步。独立应用程序依赖于没有“平台”类型的Microsoft.NETCore.App。比较https://github.com/aspnet/MusicStore/blob/dev/samples/MusicStore/project.json#L58-L61 vs https://github.com/aspnet/MusicStore/blob/dev/samples/MusicStore.Standalone/project.json#L68-L70
同样是第4步:他们需要一个运行时列表来发布,以便您获得所有正确的naitve二进制文件:https://github.com/aspnet/MusicStore/blob/dev/samples/MusicStore.Standalone/project.json#L80-L89
这应该让xcopy部署网站并将其作为控制台应用程序运行(应该有适用于Windows的MyApp.exe),但如果没有AspNetCoreModule(通过Hosting软件包安装),您将无法在IIS中运行它)。
答案 2 :(得分:0)
编辑.csproj文件并在windows,ubuntu,osx的属性组下指定RuntimeIdentifier。
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<RuntimeIdentifiers>win10-x64;osx.10.10-x64;ubuntu.14.04-x64</RuntimeIdentifiers>
</PropertyGroup>
比保存和发布不同目标机器的应用程序
dotnet publish -c release -r win10-x64
dotnet publish -c release -r osx.10.10-x64
dotnet publish -c release -r ubuntu.14.04-x64
有关详细信息,请阅读有关在Windows / Linux / Mac上创建和部署.Net Core应用程序的博客 http://www.spicy-dotnet.com/2017/10/creating-and-deploying-net-core.html