在.NET CORE
应用程序中,我在wwwroot
文件夹中使用了静态文件。 在运行它作为dotnet run
在localhost:port/
但发布该应用程序为SCD
自足开发包后顺利和正常显示index.html
文件,并运行生成.exe
文件时,static files
没有在localhost:port/
显示。访问SCD中的静态文件
在浏览器的开发者屏幕上,我找到了404 error
,这是找不到文件。
在.NET CORE
应用程序中,我在wwwroot
文件夹中使用了静态文件。 在运行它作为dotnet run
在localhost:port/
但发布该应用程序为SCD
自足开发包后顺利和正常显示index.html
文件,并运行生成.exe
文件时,static files
没有在localhost:port/
显示。访问SCD中的静态文件
在浏览器的开发者屏幕上,我找到了404 error
,这是找不到文件。
在你的project.json
中添加相应的语句:
"publishOptions": {
"include": [
"wwwroot",
"appsettings.json",
"web.config"
]
},
谢谢,它将文件复制到'publish'文件夹中,而不是我手动复制/粘贴。 –
你能帮助这个pls:http://stackoverflow.com/questions/40626872/attaching-a-file-from-zip-folder –
显然,.cs
以外的文件未打包,需要手动添加到publish
文件夹中。
我有下面的例子发送HTML文件作为电子邮件附:
和文件结构是:
project.json
{
"version": "1.0.0-*",
"buildOptions": {
"debugType": "portable",
"emitEntryPoint": true
},
"runtimes": {
"win10-x64": {},
"win10-x86": {}
},
"dependencies": {
"NETStandard.Library": "1.6.0",
"Microsoft.NETCore.Runtime.CoreCLR": "1.0.2",
"Microsoft.NETCore.DotNetHostPolicy": "1.0.1",
"MailKit" : "1.10.0"
},
"frameworks": {
"netstandard1.6": { }
}
}
program.cs
using System;
using System.IO; // for File.ReadAllText
using MailKit.Net.Smtp; // for SmtpClient
using MimeKit; // for MimeMessage, MailboxAddress and MailboxAddress
using MailKit; // for ProtocolLogger
namespace sendHTMLemail
{
public class newsLetter
{
public static void Main()
{
var message = new MimeMessage();
message.From.Add(new MailboxAddress("INFO", "[email protected]"));
message.To.Add(new MailboxAddress("MYSELF", "[email protected]"));
message.Subject = "Test Email";
var bodyBuilder = new BodyBuilder();
string htmlFilePath = "./html-files/msg.html";
bodyBuilder.Attachments.Add("./html-files/msg.html");
bodyBuilder.HtmlBody = File.ReadAllText(htmlFilePath);
message.Body = bodyBuilder.ToMessageBody();
using (var client = new SmtpClient (new ProtocolLogger ("smtp.log")))
{
client.Connect("smtp.office365.com", 587);
try{
client.Authenticate("[email protected]", "[email protected]");
}
catch{
Console.WriteLine("Authentication Faild");
}
try
{
client.Send(message);
}
catch (Exception)
{
Console.WriteLine("ERROR");
}
client.Disconnect(true);
}
}
}
}
以上工作非常细,而且publish
已准备运行下面的命令:
dotnet restore
dotnet build -r win10-x64
dotnet build -r win10-x86
dotnet publish -c release -r win10-x64
dotnet publish -c release -r win10-x86
,但同时在publish
文件夹执行.exe
文件,它给了一个错误,该文件pathTo/html-files/msg.html
未找到。
一旦我复制要求,如下publish
文件夹中的文件夹,一切都工作得很好:
注意 如果您不需要公共/静态文件被用户看到,那么你可以压缩它们,然后从内存流中读取它们,如解释here
您是否正在运行'publish'目录下的.exe文件? – svick
是@svick,实际上我尝试过两种方法,一种是“发布”内的,另一种是外部的,他们都没有工作。 –
运行时工作目录是什么? – svick