我有一個類庫,其中我使用下面的代碼從應用程序路徑訪問文件。它不會在azure上工作,因爲它無法找到應用程序路徑。因爲它可以在我的本地機器上正常工作,所以如何使它工作在天藍色。在Azure WebApp上的asp.net類庫項目中獲取文件路徑
private string GetProjectPath()
{
string SolutionName = "MyApi.sln";
//Get name of the target project which we want to test
var projectName = typeof(TerminationMatchInquiry).GetTypeInfo().Assembly.GetName().Name;
//Get currently executing test project path
var applicationBasePath = new Uri((typeof(TerminationMatchInquiry).GetTypeInfo().Assembly.CodeBase)).LocalPath;
//Find the folder which contains the solution file. We then use this information to find the
//target project which we want to test
DirectoryInfo directoryInfo = new DirectoryInfo(applicationBasePath);
do
{
var solutionFileInfo = new FileInfo(Path.Combine(directoryInfo.FullName, SolutionName));
if (solutionFileInfo.Exists)
{
return Path.GetFullPath(Path.Combine(directoryInfo.FullName, projectName));
}
directoryInfo = directoryInfo.Parent;
}
while (directoryInfo.Parent != null);
throw new Exception($"Solution root could not be located using application root {applicationBasePath}");
}
您的意思是Azure WebApp? – Youngjae
是Azure網絡應用程序 – maxspan
當然,它不會在azure上找到它!在部署應用程序時,您不會部署源代碼**僅由構建/發佈過程創建的二進制工件 – Tseng