我使用Visual Studio 2017 V15.7.3使用API模板创建了一个新的Asp.Net核心2.0项目。但是,新创建的项目无法编译,并且出现以下错误。
但是,我在另一台机器上做了同样的事情并且编译了。
Severity Code Description Project File Line Suppression State Error NU1202 Package System.Security.Cryptography.X509Certificates 4.1.0 is not compatible with netcoreapp2.0 (.NETCoreApp,Version=v2.0). Package System.Security.Cryptography.X509Certificates 4.1.0 supports: - monoandroid10 (MonoAndroid,Version=v1.0) - monotouch10 (MonoTouch,Version=v1.0) - xamarinios10 (Xamarin.iOS,Version=v1.0) - xamarinmac20 (Xamarin.Mac,Version=v2.0) - xamarintvos10 (Xamarin.TVOS,Version=v1.0) - xamarinwatchos10 (Xamarin.WatchOS,Version=v1.0) Error NU1202 Package System.Net.Primitives 4.0.11 is not compatible with netcoreapp2.0 (.NETCoreApp,Version=v2.0). Package System.Net.Primitives 4.0.11 supports: - monoandroid10 (MonoAndroid,Version=v1.0) - monotouch10 (MonoTouch,Version=v1.0) - net45 (.NETFramework,Version=v4.5) - portable-net45+win8+wp8+wpa81 (.NETPortable,Version=v0.0,Profile=Profile259) - win8 (Windows,Version=v8.0) - wp8 (WindowsPhone,Version=v8.0) - wpa81 (WindowsPhoneApp,Version=v8.1) - xamarinios10 (Xamarin.iOS,Version=v1.0) - xamarinmac20 (Xamarin.Mac,Version=v2.0) - xamarintvos10 (Xamarin.TVOS,Version=v1.0) - xamarinwatchos10 (Xamarin.WatchOS,Version=v1.0) Error NU1202 Package System.Reflection.Metadata 1.3.0 is not compatible with netcoreapp2.0 (.NETCoreApp,Version=v2.0). Package System.Reflection.Metadata 1.3.0 does not support any target frameworks. Error NU1202 Package System.Threading.Timer 4.0.1 is not compatible with netcoreapp2.0 (.NETCoreApp,Version=v2.0). Package System.Threading.Timer 4.0.1 supports: - monoandroid10 (MonoAndroid,Version=v1.0) - monotouch10 (MonoTouch,Version=v1.0) - net451 (.NETFramework,Version=v4.5.1) - portable-net451+win81+wpa81 (.NETPortable,Version=v0.0,Profile=Profile151) - win81 (Windows,Version=v8.1) - wpa81 (WindowsPhoneApp,Version=v8.1) - xamarinios10 (Xamarin.iOS,Version=v1.0) - xamarinmac20 (Xamarin.Mac,Version=v2.0) - xamarintvos10 (Xamarin.TVOS,Version=v1.0) - xamarinwatchos10 (Xamarin.WatchOS,Version=v1.0) Error NU1202 Package System.Threading.Thread 4.0.0 is not compatible with netcoreapp2.0 (.NETCoreApp,Version=v2.0). Package System.Threading.Thread 4.0.0 supports: - monoandroid10 (MonoAndroid,Version=v1.0) - monotouch10 (MonoTouch,Version=v1.0) - netcore50 (.NETCore,Version=v5.0) - xamarinios10 (Xamarin.iOS,Version=v1.0) - xamarinmac20 (Xamarin.Mac,Version=v2.0) - xamarintvos10 (Xamarin.TVOS,Version=v1.0) - xamarinwatchos10 (Xamarin.WatchOS,Version=v1.0) Error NU1202 Package System.Collections.Concurrent 4.0.12 is not compatible with netcoreapp2.0 (.NETCoreApp,Version=v2.0). Package System.Collections.Concurrent 4.0.12 supports: - monoandroid10 (MonoAndroid,Version=v1.0) - monotouch10 (MonoTouch,Version=v1.0) - net45 (.NETFramework,Version=v4.5) - portable-net45+win8+wpa81 (.NETPortable,Version=v0.0,Profile=Profile111) - win8 (Windows,Version=v8.0) - wpa81 (WindowsPhoneApp,Version=v8.1) - xamarinios10 (Xamarin.iOS,Version=v1.0) - xamarinmac20 (Xamarin.Mac,Version=v2.0) - xamarintvos10 (Xamarin.TVOS,Version=v1.0) - xamarinwatchos10 (Xamarin.WatchOS,Version=v1.0) Error NU1202 Package System.Security.Cryptography.Encoding 4.0.0 is not compatible with netcoreapp2.0 (.NETCoreApp,Version=v2.0). Package System.Security.Cryptography.Encoding 4.0.0 supports: - monoandroid10 (MonoAndroid,Version=v1.0) - monotouch10 (MonoTouch,Version=v1.0) - xamarinios10 (Xamarin.iOS,Version=v1.0) - xamarinmac20 (Xamarin.Mac,Version=v2.0) - xamarintvos10 (Xamarin.TVOS,Version=v1.0) - xamarinwatchos10 (Xamarin.WatchOS,Version=v1.0) Error NU1202 Package System.Diagnostics.Tracing 4.1.0 is not compatible with netcoreapp2.0 (.NETCoreApp,Version=v2.0). Package System.Diagnostics.Tracing 4.1.0 supports: - monoandroid10 (MonoAndroid,Version=v1.0) - monotouch10 (MonoTouch,Version=v1.0) - net45 (.NETFramework,Version=v4.5) - portable-net45+win8+wpa81 (.NETPortable,Version=v0.0,Profile=Profile111) - win8 (Windows,Version=v8.0) - wpa81 (WindowsPhoneApp,Version=v8.1) - xamarinios10 (Xamarin.iOS,Version=v1.0) - xamarinmac20 (Xamarin.Mac,Version=v2.0) - xamarintvos10 (Xamarin.TVOS,Version=v1.0) - xamarinwatchos10 (Xamarin.WatchOS,Version=v1.0) Error NU1202 Package System.AppContext 4.1.0 is not compatible with netcoreapp2.0 (.NETCoreApp,Version=v2.0). Package System.AppContext 4.1.0 supports: - monoandroid10 (MonoAndroid,Version=v1.0) - monotouch10 (MonoTouch,Version=v1.0) - netstandard (.NETStandard,Version=v0.0) - xamarinios10 (Xamarin.iOS,Version=v1.0) - xamarinmac20 (Xamarin.Mac,Version=v2.0) - xamarintvos10 (Xamarin.TVOS,Version=v1.0) - xamarinwatchos10 (Xamarin.WatchOS,Version=v1.0) Error NU1202 Package System.Collections.Immutable 1.2.0 is not compatible with netcoreapp2.0 (.NETCoreApp,Version=v2.0). Package System.Collections.Immutable 1.2.0 does not support any target frameworks. Error NU1202 Package System.Xml.XmlSerializer 4.0.11 is not compatible with netcoreapp2.0 (.NETCoreApp,Version=v2.0). Package System.Xml.XmlSerializer 4.0.11 supports: - monoandroid10 (MonoAndroid,Version=v1.0) - monotouch10 (MonoTouch,Version=v1.0) - net45 (.NETFramework,Version=v4.5) - portable-net45+win8+wp8+wpa81 (.NETPortable,Version=v0.0,Profile=Profile259) - win8 (Windows,Version=v8.0) - wp8 (WindowsPhone,Version=v8.0) - wpa81 (WindowsPhoneApp,Version=v8.1) - xamarinios10 (Xamarin.iOS,Version=v1.0) - xamarinmac20 (Xamarin.Mac,Version=v2.0) - xamarintvos10 (Xamarin.TVOS,Version=v1.0) - xamarinwatchos10 (Xamarin.WatchOS,Version=v1.0) Error NU1202 Package System.Runtime.InteropServices.RuntimeInformation 4.0.0 is not compatible with netcoreapp2.0 (.NETCoreApp,Version=v2.0). Package System.Runtime.InteropServices.RuntimeInformation 4.0.0 supports: - monoandroid10 (MonoAndroid,Version=v1.0) - monotouch10 (MonoTouch,Version=v1.0) - xamarinios10 (Xamarin.iOS,Version=v1.0) - xamarinmac20 (Xamarin.Mac,Version=v2.0) - xamarintvos10 (Xamarin.TVOS,Version=v1.0) - xamarinwatchos10 (Xamarin.WatchOS,Version=v1.0) Error NU1202 Package System.Security.Principal 4.0.1 is not compatible with netcoreapp2.0 (.NETCoreApp,Version=v2.0). Package System.Security.Principal 4.0.1 supports: - monoandroid10 (MonoAndroid,Version=v1.0) - monotouch10 (MonoTouch,Version=v1.0) - net45 (.NETFramework,Version=v4.5) - portable-net45+win8+wp8+wpa81 (.NETPortable,Version=v0.0,Profile=Profile259) - win8 (Windows,Version=v8.0) - wp8 (WindowsPhone,Version=v8.0) - wpa81 (WindowsPhoneApp,Version=v8.1) - xamarinios10 (Xamarin.iOS,Version=v1.0) - xamarinmac20 (Xamarin.Mac,Version=v2.0) - xamarintvos10 (Xamarin.TVOS,Version=v1.0) - xamarinwatchos10 (Xamarin.WatchOS,Version=v1.0) Error NU1202 Package System.Text.Encoding.CodePages 4.0.1 is not compatible with netcoreapp2.0 (.NETCoreApp,Version=v2.0). Package System.Text.Encoding.CodePages 4.0.1 supports: - monoandroid10 (MonoAndroid,Version=v1.0) - monotouch10 (MonoTouch,Version=v1.0) - xamarinios10 (Xamarin.iOS,Version=v1.0) - xamarinmac20 (Xamarin.Mac,Version=v2.0) - xamarintvos10 (Xamarin.TVOS,Version=v1.0) - xamarinwatchos10 (Xamarin.WatchOS,Version=v1.0) Error NU1202 Package System.Net.Sockets 4.1.0 is not compatible with netcoreapp2.0 (.NETCoreApp,Version=v2.0). Package System.Net.Sockets 4.1.0 supports: - monoandroid10 (MonoAndroid,Version=v1.0) - monotouch10 (MonoTouch,Version=v1.0) - xamarinios10 (Xamarin.iOS,Version=v1.0) - xamarinmac20 (Xamarin.Mac,Version=v2.0) - xamarintvos10 (Xamarin.TVOS,Version=v1.0) - xamarinwatchos10 (Xamarin.WatchOS,Version=v1.0) Error NU1202 Package System.Security.Cryptography.Csp 4.0.0 is not compatible with netcoreapp2.0 (.NETCoreApp,Version=v2.0). Package System.Security.Cryptography.Csp 4.0.0 supports: - monoandroid10 (MonoAndroid,Version=v1.0) - monotouch10 (MonoTouch,Version=v1.0) - xamarinios10 (Xamarin.iOS,Version=v1.0) - xamarinmac20 (Xamarin.Mac,Version=v2.0) - xamarintvos10 (Xamarin.TVOS,Version=v1.0) - xamarinwatchos10 (Xamarin.WatchOS,Version=v1.0) Error NU1202 Package System.Security.Cryptography.Primitives 4.0.0 is not compatible with netcoreapp2.0 (.NETCoreApp,Version=v2.0). Package System.Security.Cryptography.Primitives 4.0.0 supports: - monoandroid10 (MonoAndroid,Version=v1.0) - monotouch10 (MonoTouch,Version=v1.0) - xamarinios10 (Xamarin.iOS,Version=v1.0) - xamarinmac20 (Xamarin.Mac,Version=v2.0) - xamarintvos10 (Xamarin.TVOS,Version=v1.0) - xamarinwatchos10 (Xamarin.WatchOS,Version=v1.0) Error NU1202 Package System.Diagnostics.Contracts 4.0.1 is not compatible with netcoreapp2.0 (.NETCoreApp,Version=v2.0). Package System.Diagnostics.Contracts 4.0.1 supports: - monoandroid10 (MonoAndroid,Version=v1.0) - monotouch10 (MonoTouch,Version=v1.0) - net45 (.NETFramework,Version=v4.5) - portable-net45+win8+wp8+wpa81 (.NETPortable,Version=v0.0,Profile=Profile259) - win8 (Windows,Version=v8.0) - wp8 (WindowsPhone,Version=v8.0) - wpa81 (WindowsPhoneApp,Version=v8.1) - xamarinios10 (Xamarin.iOS,Version=v1.0) - xamarinmac20 (Xamarin.Mac,Version=v2.0) - xamarintvos10 (Xamarin.TVOS,Version=v1.0) - xamarinwatchos10 (Xamarin.WatchOS,Version=v1.0) Error NU1202 Package System.IO.Compression 4.1.0 is not compatible with netcoreapp2.0 (.NETCoreApp,Version=v2.0). Package System.IO.Compression 4.1.0 supports: - monoandroid10 (MonoAndroid,Version=v1.0) - monotouch10 (MonoTouch,Version=v1.0) - net45 (.NETFramework,Version=v4.5) - portable-net45+win8+wpa81 (.NETPortable,Version=v0.0,Profile=Profile111) - win8 (Windows,Version=v8.0) - wpa81 (WindowsPhoneApp,Version=v8.1) - xamarinios10 (Xamarin.iOS,Version=v1.0) - xamarinmac20 (Xamarin.Mac,Version=v2.0) - xamarintvos10 (Xamarin.TVOS,Version=v1.0) - xamarinwatchos10 (Xamarin.WatchOS,Version=v1.0) Error NU1202 Package System.Runtime.Loader 4.0.0 is not compatible with netcoreapp2.0 (.NETCoreApp,Version=v2.0). Package System.Runtime.Loader 4.0.0 supports: net462 (.NETFramework,Version=v4.6.2) Error NU1202 Package System.Globalization.Calendars 4.0.1 is not compatible with netcoreapp2.0 (.NETCoreApp,Version=v2.0). Package System.Globalization.Calendars 4.0.1 supports: - monoandroid10 (MonoAndroid,Version=v1.0) - monotouch10 (MonoTouch,Version=v1.0) - xamarinios10 (Xamarin.iOS,Version=v1.0) - xamarinmac20 (Xamarin.Mac,Version=v2.0) - xamarintvos10 (Xamarin.TVOS,Version=v1.0) - xamarinwatchos10 (Xamarin.WatchOS,Version=v1.0) Error NU1202 Package System.Threading.Overlapped 4.0.1 is not compatible with netcoreapp2.0 (.NETCoreApp,Version=v2.0). Package System.Threading.Overlapped 4.0.1 does not support any target frameworks. Error NU1202 Package Microsoft.Win32.Primitives 4.0.1 is not compatible with netcoreapp2.0 (.NETCoreApp,Version=v2.0). Package Microsoft.Win32.Primitives 4.0.1 supports: - monoandroid10 (MonoAndroid,Version=v1.0) - monotouch10 (MonoTouch,Version=v1.0) - xamarinios10 (Xamarin.iOS,Version=v1.0) - xamarinmac20 (Xamarin.Mac,Version=v2.0) - xamarintvos10 (Xamarin.TVOS,Version=v1.0) - xamarinwatchos10 (Xamarin.WatchOS,Version=v1.0) Error NU1202 Package System.Threading.ThreadPool 4.0.10 is not compatible with netcoreapp2.0 (.NETCoreApp,Version=v2.0). Package System.Threading.ThreadPool 4.0.10 supports: - monoandroid10 (MonoAndroid,Version=v1.0) - monotouch10 (MonoTouch,Version=v1.0) - netcore50 (.NETCore,Version=v5.0) - xamarinios10 (Xamarin.iOS,Version=v1.0) - xamarinmac20 (Xamarin.Mac,Version=v2.0) - xamarintvos10 (Xamarin.TVOS,Version=v1.0) - xamarinwatchos10 (Xamarin.WatchOS,Version=v1.0) Error NU1202 Package Microsoft.Win32.Registry 4.0.0 is not compatible with netcoreapp2.0 (.NETCoreApp,Version=v2.0). Package Microsoft.Win32.Registry 4.0.0 does not support any target frameworks. Error NU1202 Package System.Xml.XPath 4.0.1 is not compatible with netcoreapp2.0 (.NETCoreApp,Version=v2.0). Package System.Xml.XPath 4.0.1 supports: - monoandroid10 (MonoAndroid,Version=v1.0) - monotouch10 (MonoTouch,Version=v1.0) - xamarinios10 (Xamarin.iOS,Version=v1.0) - xamarinmac20 (Xamarin.Mac,Version=v2.0) - xamarintvos10 (Xamarin.TVOS,Version=v1.0) - xamarinwatchos10 (Xamarin.WatchOS,Version=v1.0) Error NU1202 Package System.Threading.Tasks.Dataflow 4.6.0 is not compatible with netcoreapp2.0 (.NETCoreApp,Version=v2.0). Package System.Threading.Tasks.Dataflow 4.6.0 does not support any target frameworks. Error NU1202 Package System.Diagnostics.Process 4.1.0 is not compatible with netcoreapp2.0 (.NETCoreApp,Version=v2.0). Package System.Diagnostics.Process 4.1.0 supports: - monoandroid10 (MonoAndroid,Version=v1.0) - monotouch10 (MonoTouch,Version=v1.0) - xamarinios10 (Xamarin.iOS,Version=v1.0) - xamarinmac20 (Xamarin.Mac,Version=v2.0) - xamarintvos10 (Xamarin.TVOS,Version=v1.0) - xamarinwatchos10 (Xamarin.WatchOS,Version=v1.0) Error NU1202 Package System.Linq.Parallel 4.0.1 is not compatible with netcoreapp2.0 (.NETCoreApp,Version=v2.0). Package System.Linq.Parallel 4.0.1 supports: - monoandroid10 (MonoAndroid,Version=v1.0) - monotouch10 (MonoTouch,Version=v1.0) - net45 (.NETFramework,Version=v4.5) - portable-net45+win8+wpa81 (.NETPortable,Version=v0.0,Profile=Profile111) - win8 (Windows,Version=v8.0) - wpa81 (WindowsPhoneApp,Version=v8.1) - xamarinios10 (Xamarin.iOS,Version=v1.0) - xamarinmac20 (Xamarin.Mac,Version=v2.0) - xamarintvos10 (Xamarin.TVOS,Version=v1.0) - xamarinwatchos10 (Xamarin.WatchOS,Version=v1.0) Error NU1202 Package System.Console 4.0.0 is not compatible with netcoreapp2.0 (.NETCoreApp,Version=v2.0). Package System.Console 4.0.0 supports: - monoandroid10 (MonoAndroid,Version=v1.0) - monotouch10 (MonoTouch,Version=v1.0) - xamarinios10 (Xamarin.iOS,Version=v1.0) - xamarinmac20 (Xamarin.Mac,Version=v2.0) - xamarintvos10 (Xamarin.TVOS,Version=v1.0) - xamarinwatchos10 (Xamarin.WatchOS,Version=v1.0) Error NU1202 Package System.Security.Cryptography.Algorithms 4.2.0 is not compatible with netcoreapp2.0 (.NETCoreApp,Version=v2.0). Package System.Security.Cryptography.Algorithms 4.2.0 supports: - monoandroid10 (MonoAndroid,Version=v1.0) - monotouch10 (MonoTouch,Version=v1.0) - xamarinios10 (Xamarin.iOS,Version=v1.0) - xamarinmac20 (Xamarin.Mac,Version=v2.0) - xamarintvos10 (Xamarin.TVOS,Version=v1.0) - xamarinwatchos10 (Xamarin.WatchOS,Version=v1.0) Error NU1202 Package System.Diagnostics.FileVersionInfo 4.0.0 is not compatible with netcoreapp2.0 (.NETCoreApp,Version=v2.0). Package System.Diagnostics.FileVersionInfo 4.0.0 supports: - monoandroid10 (MonoAndroid,Version=v1.0) - monotouch10 (MonoTouch,Version=v1.0) - xamarinios10 (Xamarin.iOS,Version=v1.0) - xamarinmac20 (Xamarin.Mac,Version=v2.0) - xamarintvos10 (Xamarin.TVOS,Version=v1.0) - xamarinwatchos10 (Xamarin.WatchOS,Version=v1.0) Warning NU1701 Package 'System.Linq.Queryable 4.0.1' was restored using '.NETFramework,Version=v4.6.1' instead of the project target framework '.NETCoreApp,Version=v2.0'. This package may not be fully compatible with your project. Watcher C:\Users\wangyi\source\repos\Strats\Watcher\Watcher.csproj 1 Warning NU1701 Package 'System.Xml.XmlSerializer 4.0.11' was restored using '.NETFramework,Version=v4.6.1' instead of the project target framework '.NETCoreApp,Version=v2.0'. This package may not be fully compatible with your project. Watcher C:\Users\wangyi\source\repos\Strats\Watcher\Watcher.csproj 1
试图重新安装VS 2017并且它仍然存在同样的问题。
更新:dotnet new webapi
出现了相同的错误
PS C:\TEMP> dotnet new webapi The template "ASP.NET Core Web API" was created successfully. This template contains technologies from parties other than Microsoft, see https://aka.ms/template-3pn for details. Processing post-creation actions... Running 'dotnet restore' on C:\TEMP\TEMP.csproj... Restoring packages for C:\TEMP\TEMP.csproj... Restoring packages for C:\TEMP\TEMP.csproj... C:\TEMP\TEMP.csproj : error NU1202: Package System.Text.Encoding.CodePages 4.0.1 is not compatible with netcoreapp2.0 (. NETCoreApp,Version=v2.0). Package System.Text.Encoding.CodePages 4.0.1 supports: C:\TEMP\TEMP.csproj : error NU1202: - monoandroid10 (MonoAndroid,Version=v1.0) C:\TEMP\TEMP.csproj : error NU1202: - monotouch10 (MonoTouch,Version=v1.0) C:\TEMP\TEMP.csproj : error NU1202: - xamarinios10 (Xamarin.iOS,Version=v1.0) C:\TEMP\TEMP.csproj : error NU1202: - xamarinmac20 (Xamarin.Mac,Version=v2.0) C:\TEMP\TEMP.csproj : error NU1202: - xamarintvos10 (Xamarin.TVOS,Version=v1.0) C:\TEMP\TEMP.csproj : error NU1202: - xamarinwatchos10 (Xamarin.WatchOS,Version=v1.0) C:\TEMP\TEMP.csproj : error NU1202: Package System.Diagnostics.Contracts 4.0.1 is not compatible with netcoreapp2.0 (.NE TCoreApp,Version=v2.0). Package System.Diagnostics.Contracts 4.0.1 supports: C:\TEMP\TEMP.csproj : error NU1202: - monoandroid10 (MonoAndroid,Version=v1.0) C:\TEMP\TEMP.csproj : error NU1202: - monotouch10 (MonoTouch,Version=v1.0) C:\TEMP\TEMP.csproj : error NU1202: - net45 (.NETFramework,Version=v4.5)
答案 0 :(得分:1)
不确定您是否仍然看到该问题,但是清除nuget缓存可以为我解决此问题。 在Visual Studio中,您可以
或者您可以运行
class NewsInfo {
static var sharedInstance = NewsInfo()
private init(){}
private (set) var generalNews:[OneNews]!{
didSet{
NotificationCenter.default.post(name:
NSNotification.Name(rawValue: "GeneralNewsIsSet"), object: nil)
}
}
func setGeneralNews(allGeneralNews:[OneNews]){
self.generalNews = allGeneralNews
}
func getGeneralNews() -> [OneNews]!{
return self.generalNews
}
}
答案 1 :(得分:0)
由于某些原因,NuGet正在推动.NET Framework包。确保唯一引用的包是Microsoft.AspNetCore.All
。如果您确实要引用特定的其他包,请确保它们实际上与.NET Core兼容。如果他们需要.NET Framework,NuGet会尝试提取特定于.NET Framework的软件包,这些软件包在定位Core时不会起作用。