我有一个.NET Core 1.0.0控制台应用程序和两个环境.我需要能够使用appSettings.dev.json并appSettings.test.json基于我在运行时设置的环境变量.对于ASP.NET Core Web应用程序来说,这似乎非常简单,通过依赖注入和IHostingEnvironment以及EnvironmentName env.变量,但是我应该如何为控制台应用程序连接(除了编写我自己使用的自定义代码Microsoft.Framework.Configuration.EnvironmentVariables)?
谢谢.
我有一个像以下网站项目:
namespace Web
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
lbResult.Text = PathTest.GetBasePath();
}
}
}
Run Code Online (Sandbox Code Playgroud)
该方法PathTest.GetBasePath()在另一个项目中定义,如:
namespace TestProject
{
public class PathTest
{
public static string GetBasePath()
{
return AppDomain.CurrentDomain.BaseDirectory;
}
}
}
Run Code Online (Sandbox Code Playgroud)
为什么...\Web\在将TestProject程序集编译到bin文件夹时显示它(换句话说,它应该显示...\Web\bin在我的想法中).
如果我修改了方法,我现在遇到了麻烦:
namespace TestProject
{
public class FileReader
{
private const string m_filePath = @"\File.config";
public static string Read()
{
FileStream fs = null;
fs = new FileStream(AppDomain.CurrentDomain.BaseDirectory + m_filePath,FileMode.Open, …Run Code Online (Sandbox Code Playgroud)