簡體   English   中英

如何刪除本地 nuget 參考

[英]How to Remove local nuget references

我將 realm package 添加到我的項目中,它工作正常,但由於某種原因,它還添加了一些我無法刪除的無效本地依賴項。 我試圖從 csproj 文件中手動刪除它們,但沒有它們的蹤跡。 我怎樣才能擺脫它們? 在此處輸入圖像描述

  1. 右鍵單擊您的項目, select Unload Project
  2. Select 卸載的項目,你會看到一個 xml 文件打開。
  3. 查找包含引用列表的<ItemGroup>
  4. 刪除不再需要的項目。
  5. 保存文件。 右鍵單擊項目並Reload它。

您已在非 sdk 網絡框架項目的 csproj 文件上添加了RuntimeIdentifier xml 節點

這就是原因。 您應該注意, RuntimeIdentifier適用於新的 sdk net core跨平台項目,而不是您的非 sdk net framework windows 項目。

RuntimeIdentifier不適用於非 sdk 網絡框架項目。

所以你必須在csproj文件中刪除這些。

<PropertyGroup>
  <RuntimeIdentifier>osx-x64</RuntimeIdentifier>
</PropertyGroup>

在此處輸入圖像描述

當我刪除它時,一切正常。

更新

這是我之前報道過的一個眾所周知的問題

問題在這里:

C:\Users\xxx\.nuget\packages\realm\10.1.1\build\Realm.props然后打開那個文件,你會看到:

在此處輸入圖像描述

您有兩點需要注意:

1) NativeReference works for ios apps rather than android apps, actually, you could just delete the NativeReference node but for the inclusiveness and comprehensiveness of the nuget package, it is not advisable to delete it.

2) NativeReference無法識別 MSBuild 屬性的值。 您不能在其中傳遞屬性值。 正如我的鏈接所暗示的那樣。

首先itemgroup condition在構建的時候確實會被vs根據條件進行處理,但是沒有構建的時候會忽略條件去檢查它的內容判斷是否有效,但是因為你的Android項目一直無法識別nativereference ,所以問題一直存在。

為了跳過這個檢測機制,你最好使用choose, when 而在這個場景中,你使用的是Android項目,所以不需要考慮nativereference不能識別屬性的問題。

建議一

Realm.props修改為:

<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <_RealmNugetNativePath Condition="'$(_RealmNugetNativePath)' == ''">$(MSBuildThisFileDirectory)..\native\</_RealmNugetNativePath>
  </PropertyGroup>
<Choose>
<When Condition="'$(TargetFrameworkIdentifier)' == 'Xamarin.iOS'">
<ItemGroup>
 <NativeReference Include="$(_RealmNugetNativePath)ios\universal\realm-wrappers.framework">
      <Kind>Framework</Kind>
      <SmartLink>False</SmartLink>
    </NativeReference>
</ItemGroup>
</When>
<When Condition="'$(TargetFrameworkIdentifier)' == 'Xamarin.Mac'">

 <ItemGroup>
    <NativeReference Include="$(_RealmNugetNativePath)..\runtimes\osx-x64\native\librealm-wrappers.dylib">
      <Kind>Dynamic</Kind>
    </NativeReference>
  </ItemGroup>
</When>
</Choose>
  <ItemGroup Condition="'$(TargetFrameworkIdentifier)' == 'Xamarin.iOS'">
   
    <Content Include="$(_RealmNugetNativePath)ios\Realm.dll.config">
      <Link>Realm.dll.config</Link>
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </Content>
  </ItemGroup>
 
  <ItemGroup Condition="'$(TargetFrameworkIdentifier)' == 'MonoAndroid'">
    <AndroidNativeLibrary Include="$(_RealmNugetNativePath)android\armeabi-v7a\librealm-wrappers.so">
      <Link>$(_RealmNugetNativePath)android\armeabi-v7a\librealm-wrappers.so</Link>
    </AndroidNativeLibrary>
    <AndroidNativeLibrary Include="$(_RealmNugetNativePath)android\x86\librealm-wrappers.so">
      <Link>$(_RealmNugetNativePath)android\x86\librealm-wrappers.so</Link>
    </AndroidNativeLibrary>
    <!-- 64bit -->
    <AndroidNativeLibrary Include="$(_RealmNugetNativePath)android\arm64-v8a\librealm-wrappers.so">
      <Link>$(_RealmNugetNativePath)android\arm64-v8a\librealm-wrappers.so</Link>
    </AndroidNativeLibrary>
    <AndroidNativeLibrary Include="$(_RealmNugetNativePath)android\x86_64\librealm-wrappers.so">
      <Link>$(_RealmNugetNativePath)android\x86_64\librealm-wrappers.so</Link>
    </AndroidNativeLibrary>
  </ItemGroup>
  <ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework'">
    <None Include="$(_RealmNugetNativePath)..\runtimes\win-x86\native\realm-wrappers.dll">
      <Link>lib\win32\x86\realm-wrappers.dll</Link>
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Include="$(_RealmNugetNativePath)..\runtimes\win-x64\native\realm-wrappers.dll">
      <Link>lib\win32\x64\realm-wrappers.dll</Link>
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
  </ItemGroup>
</Project>

建議二

2)如果您進一步使用 IOS 應用程序,您必須嘗試這些:

a)刪除Realm.props文件下的兩個NativeReference節點

b)然后將這些添加到ios.csoroj文件中:

<Choose>
<When Condition="'$(TargetFrameworkIdentifier)' == 'Xamarin.iOS'">

<ItemGroup>
<NativeReference Include="C:\Users\xxx\.nuget\packages\realm\10.1.1\native\ios\universal\realm-wrappers.framework" Kind="Framework" SmartLink="False">
</NativeReference>

</ItemGroup>
</When>
<When Condition="'$(TargetFrameworkIdentifier)' == 'Xamarin.Mac'">
     <ItemGroup>
<NativeReference Include="C:\Users\xxx\.nuget\packages\realm\10.1.1\runtimes\osx-x64\native\librealm-wrappers.dylib" Kind="Dynamic">
</NativeReference>
</ItemGroup>
  </When>

</Choose>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM