xamarin / xamarin-macios

.NET for iOS, Mac Catalyst, macOS, and tvOS provide open-source bindings of the Apple SDKs for use with .NET managed languages such as C#
Other
2.47k stars 512 forks source link

Assets created in Xcode's editor don't load #5339

Open ermau opened 5 years ago

ermau commented 5 years ago

Steps to Reproduce

  1. Create a new Cocoa project in VSM
  2. Open created Assets.xcassets in Xcode
  3. Add a new color set
  4. Attempt to load named color with NSColor.FromName

Expected Behavior

The color loads. I'd also expect the color set to appear in the VSM editor.

Actual Behavior

The NSColor is unresolved and the set does not appear in the VSM editor.

Environment

=== Visual Studio Enterprise 2019 Preview for Mac ===

Version 8.0 Preview (8.0 build 869)
Installation UUID: 8f4665a7-f65d-4647-a0cb-6581a4214f70
    GTK+ 2.24.23 (Raleigh theme)
    Xamarin.Mac 5.0.0.0 ( / b40230c0)

    Package version: 516000221

=== Mono Framework MDK ===

Runtime:
    Mono 5.16.0.221 (2018-06/b63e5378e38) (64-bit)
    Package version: 516000221

=== NuGet ===

Version: 4.7.0.5148

=== .NET Core ===

Runtime: /usr/local/share/dotnet/dotnet
Runtime Versions:
    2.1.6
    2.1.2
    2.1.1
    2.0.5
    2.0.0
SDK: /usr/local/share/dotnet/sdk/2.1.500/Sdks
SDK Versions:
    2.1.500
    2.1.302
    2.1.301
    2.1.4
    2.0.0
MSBuild SDKs: /Library/Frameworks/Mono.framework/Versions/5.16.0/lib/mono/msbuild/15.0/bin/Sdks

=== Xamarin.Profiler ===

Version: 1.6.4
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

=== Updater ===

Version: 8

=== Apple Developer Tools ===

Xcode 10.0 (14320.25)
Build 10A255

=== Xamarin.Mac ===

Version: 5.2.1.12 (Visual Studio Enterprise)
Hash: 65ec520f
Branch: 
Build date: 2018-12-05 12:06:09-0500

=== Xamarin.iOS ===

Version: 12.2.1.12 (Visual Studio Enterprise)
Hash: 65ec520f
Branch: d15-9
Build date: 2018-12-05 12:06:09-0500

=== Xamarin Designer ===

Version: 4.17.1.189
Hash: 0e3953bd9
Branch: remotes/origin/d16-0-p1
Build date: 2018-11-07 13:21:06 UTC

=== Xamarin.Android ===

Version: 9.1.4.2 (Visual Studio Enterprise)
Android SDK: /Users/ermau/Library/Developer/Xamarin/android-sdk-macosx
    Supported Android versions:
        None installed

SDK Tools Version: 26.1.1
SDK Platform Tools Version: 28.0.0
SDK Build Tools Version: 27.0.3

=== Microsoft Mobile OpenJDK ===

Java SDK: /Users/ermau/Library/Developer/Xamarin/jdk/microsoft_dist_openjdk_1.8.0.9
1.8.0-9
Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

=== Android Device Manager ===

Version: 1.2.0.1
Hash: 99d7ff4
Branch: remotes/origin/d16-0-p2~1
Build date: 2018-12-03 21:56:10 UTC

=== Xamarin Inspector ===

Version: 1.4.3
Hash: db27525
Branch: 1.4-release
Build date: Mon, 09 Jul 2018 21:20:18 GMT
Client compatibility: 1

=== Build Information ===

Release ID: 800000869
Git revision: 3c7c96b41ce6b823bf58bb89bda695448ccc97f5
Build date: 2018-12-03 21:59:44+00
Build branch: release-8.0
Xamarin extensions: 87c82bbb37a91ff539738267c414f0d6db88392c

=== Operating System ===

Mac OS X 10.13.6
Darwin 17.7.0 Darwin Kernel Version 17.7.0
    Thu Jun 21 22:53:14 PDT 2018
    root:xnu-4570.71.2~1/RELEASE_X86_64 x86_64
chamons commented 5 years ago

It appears you can work around this by creating ImageAsset items in your csproj:

    <ImageAsset Include="Assets.xcassets\FooColor.colorset\Contents.json" />
    <ImageAsset Include="Assets.xcassets\BarColor.colorset\Contents.json" />

Test Project: ColorAssetTestC.zip

spouliot commented 5 years ago

It appears the new (from Xcode) Contents.json are not read when calling actool IOW "only" the original ones (from the template) are used.

It seems we should be scanning the directory to find all of them and build the list from this (instead of storing them inside the .csproj).

@jstedfast does that sounds right ?

spouliot commented 5 years ago

There's different two issues.

  1. The VS4Mac addin does not read the files either, so what's added by Xcode is not shown when opening the asset editor. -> https://github.com/xamarin/xamarin-macios/issues/5359

  2. The (ms)build does not consider what's not in the .csproj - which should not depend on the IDE since a bot would use msbuild directly.

jstedfast commented 5 years ago

We use the .csproj because the IDE allows users to "Remove from Project" instead of "Delete from Disk", so we can't assume that just because there's a directory or a file on disk that it should be included in the build. This also had the benefit of fixing VS Windows which needed to know which files to copy over to the Mac.

anoopvaidya commented 5 years ago

I spent 4 days to find any solution for macOS project to have color assets for light and dark mode. Finally, it worked for me. Instead of using hex-color codes I used rgb. Now the VSM opens the Assets.xcassets in the IDE