【发布时间】:2020-09-08 11:14:04
【问题描述】:
我的项目基于 windows,现在我将其转换为 Linux 和 Mc。 Sp 我想为跨平台更改此代码,以便它可以在所有平台上工作。
using Microsoft.Win32;
public class Program
{
private const string DefaultInstallPath = @"C.....";
private const string ProductRegistryKey = @"......";
private static string _appPath;
//....
}
public static string AppPath
{
get
{
if (string.IsNullOrEmpty(_appPath))
{
var currentDirectory = Directory.GetCurrentDirectory();
if (Debugger.IsAttached)
{
_appPath = currentDirectory;
}
else
{
_appPath = (string)Registry.GetValue(ProductRegistryKey, "InstallPath", DefaultInstallPath);
}
if (_appPath == null)
{
_appPath = DefaultInstallPath;
}
if (!Directory.Exists(_appPath))
{
_appPath = currentDirectory;
}
}
return _appPath;
}
}
我想要适用于所有平台的代码。那我该怎么做呢?
【问题讨论】:
标签: asp.net asp.net-core .net-core asp.net-core-3.1