[英]Unable to install a Nuget Package in a .NET Framework 4.7.2 project
[英]Downloading reference-only NuGet packages using the dotnet CLI on macOS, in a Mono / .NET Framework 4.7.2 project
我是 C# 的初學者,在 CLI 上使用 macOS。 (我無法訪問用於日常開發的 IDE;我可以偶爾使用一個來執行一次性命令,但僅此而已。)
我正在嘗試將Krafs.Rimworld.Ref
package 從 NuGet 添加到我的項目中; 除其他外,這提供了一個命名空間Verse
。
這個項目必須是一個 .NET Framework 4.7.2 項目(這個也是我無法控制的); 因此,我安裝了 Mono,因為我是在 macOS 上開發的。
我的.csproj
( complete )中包含以下內容:
<PackageReference Include="Krafs.Rimworld.Ref">
<Version>1.3.3087</Version>
</PackageReference>
當我導航到包含該.csproj
的解決方案的文件夾並運行do.net restore
時,它沒有打印任何有用的信息; 只有以下內容:
❯ HelloCSharp main* dotnet restore
Determining projects to restore...
All projects are up-to-date for restore.
我遵循的編譯說明提供了以下有關如何構建的建議:
FrameworkPathOverride="$(dirname $(which mono))/../lib/mono/4.7.2-api/" \
dotnet build Source/HelloCSharpLibrary/HelloCSharpLibrary.csproj /property:Configuration=Release
不幸的是,它仍然抱怨來自僅引用 NuGet package 的Verse
命名空間丟失:
Microsoft (R) Build Engine version 16.11.0+0538acc04 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.
Determining projects to restore...
All projects are up-to-date for restore.
/Users/ec/Sync/Code/HelloCSharp/Source/HelloCSharpLibrary/Helloicate.cs(2,7): error CS0246: The type or namespace name 'Verse' could not be found (are you missing a using directive or an assembly reference?) [/Users/ec/Sync/Code/HelloCSharp/Source/HelloCSharpLibrary/HelloCSharpLibrary.csproj]
/Users/ec/Sync/Code/HelloCSharp/Source/HelloCSharpLibrary/Helloicate.cs(7,6): error CS0246: The type or namespace name 'StaticConstructorOnStartupAttribute' could not be found (are you missing a using directive or an assembly reference?) [/Users/ec/Sync/Code/HelloCSharp/Source/HelloCSharpLibrary/HelloCSharpLibrary.csproj]
/Users/ec/Sync/Code/HelloCSharp/Source/HelloCSharpLibrary/Helloicate.cs(7,6): error CS0246: The type or namespace name 'StaticConstructorOnStartup' could not be found (are you missing a using directive or an assembly reference?) [/Users/ec/Sync/Code/HelloCSharp/Source/HelloCSharpLibrary/HelloCSharpLibrary.csproj]
Build FAILED.
檢查~/.nuget/packages
,確實下載了krafs.rimworld.ref/1.3.3087/ref.net472/Assembly-CSharp.dll
。 ILSpy 顯示它包含所需的Verse
命名空間和引用。 盡管.csproj
中有PackageReference
,但我只是不明白為什么上面的do.net build
命令找不到這些引用。
(當通過 Windows 上的 GUI 完成時,所有這些工作正常,因為它當然可以。我遇到的問題僅在 macOS / Mono / CLI 上。)
所以,這不是我喜歡的解決方案,因為它沒有解釋為什么會發生錯誤——但我能夠通過使用msbuild
附帶的 msbuild 版本繞過這個問題,至少目前是這樣:
msbuild HelloCSharpSolution.sln -restore -p:Configuration=Release
(這讓我很擔心,因為這意味着我正在走出受制裁的do.net
工具;並失去do.net build
可能包括msbuild
沒有的任何其他行為......所以我將這個問題懸而未決,希望有人可以提出更好的解釋。)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.