San*_*der 6 nuget portable-class-library visual-studio-2015 .net-4.6 project.json
我有一个针对.NET 4.6和通用Windows平台的可移植类库项目.这个类库只包含一个类,其构造函数中包含以下代码行:
Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()));
Run Code Online (Sandbox Code Playgroud)
现在,我在同一解决方案中创建一个新的.NET 4.6控制台应用程序项目,并向可移植类库添加项目引用.调用包含上述代码行的方法会在运行时导致以下异常:
Could not load file or assembly 'System.IO.FileSystem, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
Run Code Online (Sandbox Code Playgroud)
我在这做错了什么?没有编译时错误或警告.
似乎System.IO.FileSystem是一个通过NuGet提供的库,作为Microsoft.NETCore mega-package的一部分.好吧,也许我需要将这个包明确地添加到任何使用我的可移植类库的项目中.我试图这样做.
Could not install package 'Microsoft.NETCore.Platforms 1.0.0'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.6', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.
Run Code Online (Sandbox Code Playgroud)
这种方法没有运气.
虽然网上没有明确的信息,但我读了一些关于基于NuGet线束或构建系统的新project.json的花絮.为了实验,我在控制台应用程序项目中创建了以下project.json文件:
{
"dependencies": {
},
"frameworks": {
"net46": { }
},
"runtimes": {
"win-anycpu": { }
}
}
Run Code Online (Sandbox Code Playgroud)
有用!运行时错误消失了!但是,我很快发现这不是正确的解决方案,也不是完整的解决方案.我开始编写一些代码来读取配置节值,这涉及到使用IConfigurationSectionHandler接口,并得到以下编译时错误:
error CS0246: The type or namespace name 'IConfigurationSectionHandler' could not be found (are you missing a using directive or an assembly reference?)
Run Code Online (Sandbox Code Playgroud)
此接口是系统程序集的一部分.我看到对此程序集的引用,但它有一个黄色感叹号图标,并在警告窗口中显示警告:
The referenced component 'System' could not be found.
Run Code Online (Sandbox Code Playgroud)
这是我没有想法的地方.我错过了一些完全明显的东西吗
我已经找到了解决方案。我最初的尝试是将 Microsoft.NETCore 包安装到控制台应用程序中,导致出现我原来的帖子中显示的错误。
但是,如果我只安装范围狭窄的软件包,例如 System.IO.FileSystem,那么我就会成功并且应用程序可以正常工作。显然,Microsoft.NETCore“主包”有一些特殊之处,导致它无法正确安装到依赖项目中。
| 归档时间: |
|
| 查看次数: |
1039 次 |
| 最近记录: |