.net6 core webapi 如何所有指定 privatePath
时间: 2024-04-30 11:23:24 浏览: 21
在 .NET 6 Core Web API 中,可以通过在应用程序配置文件(appsettings.json)中指定 privatePath 来加载程序集。
在 appsettings.json 文件中添加以下代码:
```json
{
"runtimeOptions": {
"additionalProbingPaths": [
"C:\\path\\to\\your\\private\\folder",
"D:\\path\\to\\your\\other\\private\\folder"
]
}
}
```
其中,additionalProbingPaths 属性指定了一个字符串数组,其中包含所有要加载程序集的 privatePath 路径。这些路径可以是本地计算机上的绝对路径,也可以是网络共享路径。
还可以通过代码设置 privatePath:
```csharp
var configuration = new ConfigurationBuilder()
.AddJsonFile("appsettings.json", optional: true)
.Build();
var runtimeOptions = new RuntimeOptions();
configuration.GetSection("runtimeOptions").Bind(runtimeOptions);
var privatePaths = runtimeOptions.AdditionalProbingPaths;
```
这将从 appsettings.json 文件中读取 additionalProbingPaths 属性,并将其绑定到 RuntimeOptions 对象上。然后,可以使用 AdditionalProbingPaths 属性获取 privatePath 数组。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)