简体   繁体   English

如何从 Xamarin Forms iOS 资产目录中删除“未知”图像

[英]How to removed "Unknown" images from Xamarin Forms iOS Asset Catalog

When updating images in an Asset Catalog for a Xamarin Forms iOS app, I sometime end up with extra images showing in the image set and sometimes the correct images are not assigned to the correct @1x, @2x etc. I also get this sometimes when I attempt to merge changes to my images between to versions of my project.在为 Xamarin Forms iOS 应用程序更新资产目录中的图像时,有时我有时会在图像集中显示额外的图像,有时会在图像集中显示正确的图像,有时当@2x 等未分配给我尝试将我的图像更改合并到我的项目版本之间。 I have been unable to clean out these images and there is no option to un-assign when you right click on these images in the asset catalog.我无法清除这些图像,并且当您在资产目录中右键单击这些图像时,没有选项可以取消分配。 Even deleting image set from the asset catalog via the Visual Studio IDE did not seem to work correctly as I then started getting some compile time errors that image files could not be found in the Assets.xcasstes folder.即使通过 Visual Studio IDE 从资产目录中删除图像集似乎也无法正常工作,因为我开始收到一些编译时错误,即在 Assets.xcasstes 文件夹中找不到图像文件。 Any ideas how to correctly merge / handle this type of situation?任何想法如何正确合并/处理这种情况? I would prefer not to manually re-update the images in the second versiomn (ie branch) of my project.我不希望手动重新更新我项目的第二个版本(即分支)中的图像。

So using the steps below, I was able to clean things up but it is a very manual process.所以使用下面的步骤,我能够清理东西,但这是一个非常手动的过程。 Still looking for a good way to merge iOS images between branches.仍在寻找一种在分支之间合并 iOS 图像的好方法。 The steps below are for VS 2019 on the PC.以下步骤适用于 PC 上的 VS 2019。

FYI - if your project is version controlled, I suggest performing a check in after every change that is made.仅供参考 - 如果您的项目是版本控制的,我建议在每次更改后执行检查。

  1. Go into the image set that has the 'unknow' images in and unset any images that are actually set. Go 进入包含“未知”图像的图像集中,并取消设置任何实际设置的图像。 (You do this by right clicking in the image and selecting unset from the popup menu.) Save the project / assets after this has been done. (您可以通过右键单击图像并从弹出菜单中选择取消设置来执行此操作。)完成后保存项目/资产。
  2. Once all images have been unset and you only see the 'unknown' images in the image set, select the image set name in the left hand pane and click the delete button near the top left hand area of the asset manager window.取消设置所有图像后,您只能看到图像集中的“未知”图像,select 左侧窗格中的图像集名称,然后单击资产管理器 window 左上方区域附近的删除按钮。 Save the project again.再次保存项目。
  3. Click on the iOS project in the solution explorer and select the 'Show all files' option in the top tool bar of the solution explorer window.单击解决方案资源管理器中的 iOS 项目和 select 解决方案资源管理器 window 顶部工具栏中的“显示所有文件”选项。 You should now see a folder named Assets.xcassets under your iOS project.您现在应该在 iOS 项目下看到一个名为 Assets.xcassets 的文件夹。
  4. Expand the Assets.xcassets folder and ensure your do not see a folder for the image set you deleted.展开 Assets.xcassets 文件夹并确保您没有看到您删除的图像集的文件夹。 For example, if you delete an image set named 'help', ensure you do not see a folder named help.imageset under the Assets.xcassets folder.例如,如果您删除名为“help”的图像集,请确保在 Assets.xcassets 文件夹下看不到名为 help.imageset 的文件夹。 If you do see the folder for the image set you just deleted, you may need to manually go into you file explorer and delete the folder from you disk drive.如果您确实看到刚刚删除的图像集的文件夹,您可能需要手动将 go 放入文件资源管理器并从磁盘驱动器中删除该文件夹。
  5. Once the folder for the image set no longer exists in Assets.xcassets folder, I highly recommend cleaning your complete project.一旦图像集的文件夹不再存在于 Assets.xcassets 文件夹中,我强烈建议您清理整个项目。
  6. Next right click on the iOS project and select 'Unload Project' from the popup menu.接下来从弹出菜单中右键单击 iOS 项目和 select '卸载项目'。
  7. After the project has been unloaded, the XXX.iOS.csproj file (where XXX is the name of your project) should automatically open in the Visual Studio editor.卸载项目后,XXX.iOS.csproj 文件(其中 XXX 是项目的名称)应在 Visual Studio 编辑器中自动打开。 You now need to search this csproj file for all instance of the image set name you deleted and remove any XML entries you find.您现在需要在此 csproj 文件中搜索您删除的映像集名称的所有实例,并删除您找到的所有 XML 条目。 For example, if I deleted the 'config' image set and I found the following entries in my csproj file, I would delete all the XML entries.例如,如果我删除了“配置”图像集,并且在我的 csproj 文件中找到了以下条目,我将删除所有 XML 条目。 NOTE: I can't get the XML to actually display here so I put it in a separate answer so everyone can see it.注意:我无法在此处实际显示 XML,因此我将其放在单独的答案中,以便每个人都可以看到。

IMPORTANT.. - Also - make sure in the folders under Assets.xcassets ensure there is no Images.imageset folder unless you actually use an asset image set named Images.重要.. - 另外 - 确保在 Assets.xcassets 下的文件夹中确保没有 Images.imageset 文件夹,除非您实际使用名为 Images 的资产图像集。 Otherwise delete this folder and ensure the folder / files are not referenced in the iOS.csproj file.否则删除此文件夹并确保在 iOS.csproj 文件中未引用该文件夹/文件。

  1. Once you have removed all the entries from images that are no longer part of your asset catalog, save the iOS csproj.从不再属于资产目录的图像中删除所有条目后,请保存 iOS csproj。 Then right mouse button click on the iOS project in your solution and select 'Reload Project'.然后右键单击解决方案中的 iOS 项目和 select '重新加载项目'。

  2. You should now be able to re-compile the project with no errors.您现在应该能够重新编译项目而不会出现错误。 REMEBER - check-in your project to your version control system frequently and especially at this point.记住 - 经常将您的项目签入到您的版本控制系统,尤其是此时。

  3. Now you can go back into you Asset Catalog and re-add the needed image sets.现在您可以将 go 返回到您的资产目录并重新添加所需的图像集。

Everything should work correctly after this point.在此之后,一切都应该正常工作。

So for some reason, I cannot get the XML code I posted above to actually display so I am going to try to post it here.所以由于某种原因,我无法让我在上面发布的 XML 代码实际显示,所以我将尝试将其发布在这里。

<ImageAsset Include="Assets.xcassets\config.imageset\config.png">
  <Visible>false</Visible>
</ImageAsset>
<ImageAsset Include="Assets.xcassets\config.imageset\config@2x.png">
  <Visible>false</Visible>
</ImageAsset>
<ImageAsset Include="Assets.xcassets\config.imageset\config@3x.png">
  <Visible>false</Visible>
</ImageAsset>
<ImageAsset Include="Assets.xcassets\config.imageset\Contents.json">
  <Visible>false</Visible>
</ImageAsset>

<ItemGroup>
  <ImageAsset Include="Assets.xcassets\Images.imageset\qrbuttonlight32.png">
    <Visible>false</Visible>
  </ImageAsset>
</ItemGroup>
<ItemGroup>
  <ImageAsset Include="Assets.xcassets\Images.imageset\qrbuttonlight64.png">
   <Visible>false</Visible>
  </ImageAsset>
</ItemGroup>
<ItemGroup>
  <ImageAsset Include="Assets.xcassets\Images.imageset\qrbuttonlight96.png">
   <Visible>false</Visible>
  </ImageAsset>
</ItemGroup>

You need to make sure you delete the complete XML tag - in this case it would be the entire ImageAsset XML node for each file in the config imageset.您需要确保删除完整的 XML 标记 - 在这种情况下,它将是配置图像集中每个文件的整个 ImageAsset XML 节点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM