heroku网站上的主页链接到一个不存在的github页面,因此我无法使用它。 https://elements.heroku.com/buttons/herokumx/herokumxnet https://github.com/herokumx/herokumxnet
我确实发现很多SO帖子链接到这个构建包和示例应用程序。 https://github.com/jincod/dotnetcore-buildpack https://github.com/jincod/AspNet5DemoApp
我尝试部署上述应用程序的完全未修改版本(您可以自己重复),但构建过程失败,没有特定错误。这是部署日志。
它抱怨它无法找到xproj.metaproj,我从中读到的是一个动态创建的元项目。通常用于构建服务器。所以我假设构建过程在某些时候失败了,但我不知道在哪里或如何。有什么东西可以添加到构建包中以获得更具体的构建错误吗?
我尝试了几次新鲜克隆/使用内置模板系统但是我总是遇到相同的构建错误。
这是一个错误吗?或者我做错了什么?
...
remote: APT packages Installled
remote: Installing dotnet
remote:
remote: Welcome to .NET Core!
remote: ---------------------
remote: Learn more about .NET Core @ https://aka.ms/dotnet-docs. Use dotnet
--he lp to see available commands or go to https://aka.ms/dotnet-cli-docs.
remote:
remote: Telemetry
remote:--------------
remote: The .NET Core tools collect usage data in order to improve your experien ce. The data is anonymous and does not include commandline arguments. The data i s collected by Microsoft and shared with the community. remote: You can opt out of telemetry by setting a DOTNET_CLI_TELEMETRY_OPTOUT en vironment variable to 1 using your favorite shell. remote: You can read more about .NET Core tools telemetry @ https://aka.ms/dotne t-cli-telemetry.
remote:
remote: Configuring...
remote: -------------------
remote: A command is running to initially populate your local package cache, to improve restore speed and enable offline access. This command will take up to a minute to complete and will only happen once. remote: Decompressing 100% 2659 ms
remote: Expanding 100% 8029 ms
remote: /tmp/build_bb0646bd8303182f6bd73ce264103dff/dotnet/sdk/1.0.0-preview5-00 4232/NuGet.targets(164,5):
error MSB3202: The project file "/tmp/build_bb0646bd8 303182f6bd73ce264103dff/src/AspNet5DemoApp/AspNet5DemoApp.xproj.metaproj" was not found. [/tmp/build_bb0646bd8303182f6bd73ce264103dff/AspNet5DemoApp.sln]
remote: ! Push rejected, failed to compile ASP.NET Core app.
remote:
remote: ! Push failed
remote: Verifying deploy...
remote:
remote: ! Push rejected to ****.
remote:
Warning: Your console font probably doesn't support Unicode. If you experience strange characters in the output, consider switching to a TrueType font such as Consolas! To https://git.heroku.com/****.git !
[remote rejected] master -> master (pre-receive hook declined) error: failed to push some refs to 'https://git.heroku.com/****.git'
编辑:我也试过这个构建包,同样没有错误 http://github.com/heroku/dotnet-buildpack.git
remote: installing https://github.com/friism/mono-builder/releases/download/v4.0
.1.44/mono-4.0.1.44.tar.gz
remote: ! Push rejected, failed to compile ASP.NET 5 app.
edit2:尝试使用相同的项目文件等在Windows上复制构建脚本,这一切都很好。
dotnet publish project.json --output pathtoproject\heroku-output\ --configuration Release
Publishing AspNet5DemoApp for .NETCoreApp,Version=v1.0
Project AspNet5DemoApp (.NETCoreApp,Version=v1.0) will be compiled because expected outputs are missing
Compiling AspNet5DemoApp for .NETCoreApp,Version=v1.0
Compilation succeeded.
0 Warning(s)
0 Error(s)
Time elapsed 00:00:02.4511992
publish: Published to ...\heroku-output\
Published 1/1 projects successfully
Edit3:我编辑了要添加的构建包 - - 详细但输出没有变化。是否有某种流我需要输出输出,以便我可以读取任何可能的错误?
答案 0 :(得分:1)
我使用noliar的buildpack来成功获得最小的.net核心 应用程序启动并运行。
步骤:
1:找到您存放git存储库的文件夹。
2:RightClick - > Git Bash在这个文件夹中。
3:Heroku创建my-app-name --buildpack https://github.com/noliar/dotnet-buildpack.git
4:响应应该给你git url,克隆它:
$ git clone https://git.heroku.com/my-app-name.git
5:将project.json和Program.cs复制并粘贴到my-app-name的根目录中 夹。 project.json的内容:
{
"version": "1.0.0-*"
,
"buildOptions":
{
"debugType": "portable"
,
"emitEntryPoint": true
}
,
"dependencies": {}
,
"frameworks":
{
"netcoreapp1.0":
{
"dependencies":
{
"Microsoft.NETCore.App":
{
"type": "platform",
"version": "1.0.0"
}
,
"Microsoft.AspNetCore.Server.Kestrel":"1.0.0"
}
,
"imports": "dnxcore50"
}
}
}
Program.cs的内容:基于最小的asp.net核心应用教程 这里:http://ardalis.com/the-minimal-aspnet-core-app附加内容 让应用程序绑定正确的端口。
//using System;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
////////////////////////////////////////////////////////////////
//https://msdn.microsoft.com/en-us/library/system.environmentvariabletarget(v=vs.110).aspx
// This example demonstrates the
// Environment.GetEnvironmentVariable,
// Environment.SetEnvironmentVariable, and
// Environment.GetEnvironmentVariables overloaded methods.
using System;
using System.Collections;
using Microsoft.Win32;
////////////////////////////////////////////////////////////////
using System.Linq; //<--to get string[].First extention
namespace ConsoleApplication
{
///<summary>
///This class stores the url that the heroku app will launch on.
///It also stores a debug message variable that we can print out
///to the application.
///</summary>
public class UrlData
{
/// <summary> The url in format such as "http://localhost:5000"
/// that the application will attach to. </summary>
public string url = null;
/// <summary> A debug message that will give us some insight into what happened
/// in the function that produced the .url component of the UrlData. </summary>
public string debug_message = "[DEBUG_MSG_NOT_SET]";
}
public class Program
{
public static UrlData
GetUrl(string[] args)
{
//inn=="arguments inputs by priority"
string[] inn = new string[3]; //3 elements.
//inn[0] = "[NOTHING_FOUND]";
inn[0] = String.Join(" | ", args);
//NOTE: Using "$PORT" and "PORT" both will cause crash on heroku:
inn[1] = Environment.GetEnvironmentVariable("$PORT"); //with "$"
//inn[2] = Environment.GetEnvironmentVariable("PORT"); //NO "$"
//Get first non-null and non-empty entry in array:
String dyna_port = null;
if(true == String.IsNullOrEmpty( inn[0] )){
//Simple processing:
dyna_port = inn.FirstOrDefault( s => !string.IsNullOrEmpty(s) );
}else{
//Parse the command line args:
//Which will look like:
// --server.urls | 5001 | 5002 | 5003
string[] port_args = inn[0].Split('|');
string port_arg_name = port_args[0];
dyna_port = port_args[1];
}
String port_num = (String.IsNullOrEmpty( dyna_port )) ?
"4998" : dyna_port;
String use_url = "[NOT_SET_USE_URL]";
if(port_num.Contains("http") ){
//The command-line likely injected an argument like:
//"http://5000:80" for the port to use.
use_url = port_num;
}else{
//The command-line likely injected an argument like:
//"5000" for the server.urls.
//Interpret it as "Port #5000"
use_url = "http://localhost:" + port_num;
}
//res_msg == "response message"
String nl = "\n";
String res_msg = "[Working From Port#]:" + port_num + nl +
"|inn[0]==" + inn[0] + nl +
"|inn[1]==" + inn[1] + nl +
"|inn[2]==" + inn[2] ;
UrlData results = new UrlData();
results.url = use_url;
results.debug_message = res_msg;
return results;
}
public static void Main(string[] args)
{
//Step#1: Get Url to operate on:
UrlData ud = GetUrl( args ); //ud=="url + debug-message"
//Uncondensed Version, so you can see what classes are being
//Used where in the chaining:
Microsoft.AspNetCore.Hosting.WebHostBuilder w1;
Microsoft.AspNetCore.Hosting.IWebHostBuilder w2;
Microsoft.AspNetCore.Hosting.IWebHostBuilder w2_5; //2_5 == 2.5
Microsoft.AspNetCore.Hosting.IWebHostBuilder w3;
Microsoft.AspNetCore.Hosting.IWebHost w4;
w1 = new WebHostBuilder();
w2 = w1.UseKestrel();
w2_5 = w2.UseUrls( ud.url );
w3 = w2_5.Configure(
a => a.Run(c => c.Response.WriteAsync(ud.debug_message))
);
w4 = w3.Build();
w4.Run();
Console.WriteLine("[HELLO_WORLD]");
}
}
}
注意:很多代码都非常混乱和实验性。但它会 建立。有一些工作总是很好。
第6步:
关于git bash:
$ git add .
$ git commit
$ dotnet restore
$> dotnet run
注意:如果您没有为命令行安装.NET CLI, 你需要它。确保您的应用程序是至关重要的 在尝试推送它们之前正确编译。它简化了 故障排除。
第7步:应用程序现在应该正在运行 localhost:4998,如果您没有配置PORT 本地计算机上的环境变量。
步骤8:如果它运行,请继续进行git push和 该项目应该成功部署。 更多提示: 1. Heroku日志 - 帮我弄清楚出了什么问题。
阅读buildpack源代码并查找$ PORT的位置 引用。
看起来.net应用程序无法访问$ PORT环境变量 在heroku上运行时,需要通过命令注入端口 线参数。 noliar buildpack的目的是做什么。
- 醇>
这个人的帖子帮助我理解了我正在使用的一些构建脚本。特别是这一行:
dotnet run --server.urls http://+:8080
文章:
https://blog.jenyay.com/running-asp-net-core-in-heroku/
希望这有帮助。我花了很多时间研究这个问题 出。实际上是希望我能够回到你的身边 张贴以找到其他人回答。
另外,对于C#代码的缩进感到抱歉。我不得不爆炸它 所有人都可以通过。