1
以下のコードをコアに移植します。しかし、コードは(例:ケストレル上)を実行しているチェックするとにかくあるかテスト(例:NUnitの上の)上で実行されているが、私はこの _hostingEnvirontmentを実行しようとしました アプリケーションの実行またはテストの実行を確認します。
if (HostingEnvironment.IsHosted)
{
//hosted
return HostingEnvironment.MapPath(path);
}
//not hosted. For example, run in unit tests
var baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
path = path.Replace("~/", "").TrimStart('/').Replace('/', '\\');
return Path.Combine(baseDirectory, path);
はIHostingEnvironment
if (I MUST CHECK IS HOSTED OR NOT)
{
//hosted
return _hostingEnvironment.ContentRootPath + path;
}
//not hosted. For example, run in unit tests
var baseDirectory = AppContext.BaseDirectory;
path = path.Replace("~/", "").TrimStart('/').Replace('/', '\\');
return Path.Combine(baseDirectory, path);
これは基本的なフレームワークです。私は最小限の変更で移植しようとしています。とにかくあなたのアイデアを念頭に置いて、これを行う最善の方法です。しかし、私の質問には答えません。 – sonstiq