VS for Mac - files visible in IDE not in .csproj file

JamesLaveryJamesLavery GBBeta, University ✭✭✭✭✭
edited February 1 in Visual Studio

I'm probably going mad/senile but I've got a problem with my .csproj file seemingly not being updated when files are added to the project.

Some background
The background to this is that in our Xamarin.Forms project, a colleague copied/pasted and then reused a XAML page and code-behind. If you don't do it right, you get the

ListButtonControl.xaml

and

ListButtonControl.xaml.cs

files appearing next to each other in the project, rather than the xaml.cs being nested under the xaml. This also causes pages using the control not to disply - so it's not just a cosmetic IDE thing. The solution is to remove them (but not delete them) and then add a file of the same name and take the prompt to add the existing file.

The Problem
So, having done this, I noticed that no changes were flagged in SourceTree (our Git client) for the .csproj file.

Looking inside the .csproj file, there is no mention of ListButtonControl or even the folder they're contained in.

The project is a .Net Standard 2.0 library holding the cross-platform elements for a Xamarin.Forms project.

The upshot is that fixing the files in the solution is not going to get pushed to Git, because the .csproj file hasn't changed.

Am I forgetting/missing something regarding where this project metadata is stored?

Version information:

=== Visual Studio Community 2017 for Mac ===

Version 7.7.3 (build 43)
Installation UUID: 650b4c91-c7f5-4ee5-ad70-6f178f314906
GTK+ 2.24.23 (Raleigh theme)
Xamarin.Mac 4.4.1.178 (master / eeaeb7e6)

Package version: 516000221

=== Mono Framework MDK ===

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

=== NuGet ===

Version: 4.8.0.5385

=== .NET Core ===

Runtime: /usr/local/share/dotnet/dotnet
Runtime Versions:
2.1.5
2.1.2
2.1.1
2.0.5
SDK: /usr/local/share/dotnet/sdk/2.1.403/Sdks
SDK Versions:
2.1.403
2.1.302
2.1.301
2.1.4
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: 11

=== Apple Developer Tools ===

Xcode 10.1 (14460.46)
Build 10B61

=== Xamarin.Mac ===

Version: 5.2.1.13 (Visual Studio Community)
Hash: a4332c90
Branch:
Build date: 2019-01-11 13:08:10-0500

=== Xamarin.iOS ===

Version: 12.2.1.13 (Visual Studio Community)
Hash: a4332c90
Branch: d15-9
Build date: 2019-01-11 13:08:09-0500

=== Xamarin.Android ===

Version: 9.1.5.1 (Visual Studio Community)
Android SDK: /Users/jameslavery/Library/Developer/Xamarin/android-sdk-macosx
Supported Android versions:
2.3 (API level 10)
4.0.3 (API level 15)
4.1 (API level 16)
4.3 (API level 18)
4.4 (API level 19)
5.0 (API level 21)
5.1 (API level 22)
6.0 (API level 23)
7.0 (API level 24)
7.1 (API level 25)
8.0 (API level 26)
8.1 (API level 27)

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

=== Microsoft Mobile OpenJDK ===

Java SDK: /Users/jameslavery/Library/Developer/Xamarin/jdk/microsoft_dist_openjdk_1.8.0.9
openjdk version "1.8.0-9"
OpenJDK Runtime Environment (build 1.8.0-9-microsoft-b00)
OpenJDK 64-Bit Server VM (build 25.71-b00, mixed mode)

Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

=== Android Device Manager ===

Version: 7.7.1.0
Hash: 06ceaea1

=== 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: 707030043
Git revision: 5896ab2acba037c62271742e9e56b900c96c1d8f
Build date: 2019-01-15 21:18:33+00
Build branch: release-7.7
Xamarin extensions: e5b43ba963b7b407aa5b9f2c59018c32a709e6ab

=== Operating System ===

Mac OS X 10.13.6
Darwin 17.7.0 Darwin Kernel Version 17.7.0
Fri Nov 2 20:43:16 PDT 2018
root:xnu-4570.71.17~1/RELEASE_X86_64 x86_64

=== Enabled user installed extensions ===

LiveXAML 1.3.31
MFractor 3.7.5
MvvmCross Template pack 2.0.1
NuGet Package Management Extensions 0.14
Template Creator 0.4
Redth's Addins 1.0.9
Internet of Things (IoT) development (Preview) 7.5

Posts

  • mattwardmattward GBMember Xamurai

    .NET Standard project used with Xamarin.Forms is the new sdk style projects. These typically do not hold information about the files. The Microsoft.NET.Sdk has various pre-defined wildcard msbuild items that automatically include these files. Such as:

    <Compile Include="**\*.cs" />
    

    So your project file would not have anything in unless you choose to modify certain properties on that file which are not defined by the implicit wildcard added by the .NET Core sdk.

    Xamarin.Forms itself defines several MSBuild wildcards for .xaml files.

    <ItemGroup Condition="'$(EnableDefaultItems)'=='True' And '$(EnableDefaultXamlItems)'=='True' And '$(EnableDefaultEmbeddedResourceItems)'=='True'">
        <Compile Update="**\*.xaml$(DefaultLanguageSourceExtension)" DependentUpon="%(Filename)" SubType="Code" />
        <None Remove="**\*.xaml" Condition="'$(EnableDefaultNoneItems)'=='True'" />
    </ItemGroup>
    

    If your project file has items for the .xaml or .xaml.cs file this can break the nesting.

    On adding new files to the project, if the file properties match what is defined by these implicit wild cards then nothing will be added to the project file itself.

  • JamesLaveryJamesLavery GBBeta, University ✭✭✭✭✭
    Thank you - that explains it!
  • JamesLaveryJamesLavery GBBeta, University ✭✭✭✭✭
    edited February 4

    @mattward - One follow-up. Out of interest, how does VS know to nest the XAML and XAML.cs files? There's a difference between adding the files separately (and so they appear separately in the IDE and cause errors at runtime) and creating a new file (and so they appear nested in the IDE and work).

    Edit Actually this is more than an 'out of interest'. I've fixed the problem in my branch, but without file changes being detected by GitHub and pushed, I can't see the fix making it to the remote repo and our build!

  • mattwardmattward GBMember Xamurai

    The file nesting is also based on MSBuild metadata. Xamarin.Forms defines the DependentUpon property for xaml.cs files. This DependentUpon information is used by VS Mac to work out if a file should be nested.

    I would look in the .csproj to see what happens after you make changes. If they are not nested I would guess a new MSBuild item has been added for one or both of the files in the project file. By adding the files separately are you creating a new file with the new file dialog (one for .xaml and one for .xaml.cs) or adding them from disk?

  • JamesLaveryJamesLavery GBBeta, University ✭✭✭✭✭

    That makes sense - but I'm not seeing any difference in my .csproj file between the nested/un-nested situations. Are MSBuild settings held in a different file?

  • mattwardmattward GBMember Xamurai

    Can you post the repro steps? The MSBuild information for the xaml files is in the Xamarin.Forms NuGet package. My guess right now is that adding the files individually is causing the DependentUpon information to not be set correctly.

  • JamesLaveryJamesLavery GBBeta, University ✭✭✭✭✭

    The repro steps are:

    1. Add a new XAML ContentView or PageView file to a .Net Standard project.
    2. XAML and XAML.cs files are nested correctly - project runs OK.
    3. Remove files from project (but don't delete from disk)
    4. Add files from disk individually
    5. XAML and XAML.cs files are not nested - project builds but sometimes produces a run-time error (or in fact runs but just doesn't show the relevant Page.

    Unfortunately note the sometimes above. I've just tried steps 4 and 5 (after a full clean and obliterate of output files), so that the files are not nested, and the project builds and runs fine. However, I definitely had problem before, which was only fixed by using the 'create a new file of the same name and adding existing files when prompted' method.

    I'm using Xamarin.Forms 3.4.0.1029999 - other version information below.

    === Visual Studio Community 2017 for Mac ===

    Version 7.7.4 (build 1)
    Installation UUID: 650b4c91-c7f5-4ee5-ad70-6f178f314906
    GTK+ 2.24.23 (Raleigh theme)
    Xamarin.Mac 4.4.1.178 (master / eeaeb7e6)

    Package version: 516000221
    

    === Mono Framework MDK ===

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

    === NuGet ===

    Version: 4.8.0.5385

    === .NET Core ===

    Runtime: /usr/local/share/dotnet/dotnet
    Runtime Versions:
    2.1.5
    2.1.2
    2.1.1
    2.0.5
    SDK: /usr/local/share/dotnet/sdk/2.1.403/Sdks
    SDK Versions:
    2.1.403
    2.1.302
    2.1.301
    2.1.4
    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: 11

    === Apple Developer Tools ===

    Xcode 10.1 (14460.46)
    Build 10B61

    === Xamarin.Mac ===

    Version: 5.2.1.13 (Visual Studio Community)
    Hash: a4332c90
    Branch:
    Build date: 2019-01-11 13:08:10-0500

    === Xamarin.iOS ===

    Version: 12.2.1.13 (Visual Studio Community)
    Hash: a4332c90
    Branch: d15-9
    Build date: 2019-01-11 13:08:09-0500

    === Xamarin.Android ===

    Version: 9.1.5.1 (Visual Studio Community)
    Android SDK: /Users/jameslavery/Library/Developer/Xamarin/android-sdk-macosx
    Supported Android versions:
    2.3 (API level 10)
    4.0.3 (API level 15)
    4.1 (API level 16)
    4.3 (API level 18)
    4.4 (API level 19)
    5.0 (API level 21)
    5.1 (API level 22)
    6.0 (API level 23)
    7.0 (API level 24)
    7.1 (API level 25)
    8.0 (API level 26)
    8.1 (API level 27)

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

    === Microsoft Mobile OpenJDK ===

    Java SDK: /Users/jameslavery/Library/Developer/Xamarin/jdk/microsoft_dist_openjdk_1.8.0.9
    openjdk version "1.8.0-9"
    OpenJDK Runtime Environment (build 1.8.0-9-microsoft-b00)
    OpenJDK 64-Bit Server VM (build 25.71-b00, mixed mode)

    Android Designer EPL code available here:
    https://github.com/xamarin/AndroidDesigner.EPL

    === Android Device Manager ===

    Version: 7.7.5.0
    Hash: 06ceaea1

    === 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: 707040001
    Git revision: 2a4679454f31c8bb887cfd181ea133c9149d3cad
    Build date: 2019-01-30 16:18:21+00
    Build branch: release-7.7.4
    Xamarin extensions: c8b4305fd4c60b9c25947072eb150fdc3a5aa2b5

    === Operating System ===

    Mac OS X 10.13.6
    Darwin 17.7.0 Darwin Kernel Version 17.7.0
    Fri Nov 2 20:43:16 PDT 2018
    root:xnu-4570.71.17~1/RELEASE_X86_64 x86_64

    === Enabled user installed extensions ===

    LiveXAML 1.3.31
    MFractor 3.7.5
    MvvmCross Template pack 2.0.1
    NuGet Package Management Extensions 0.14
    Template Creator 0.4
    Redth's Addins 1.0.9
    Internet of Things (IoT) development (Preview) 7.5

  • mattwardmattward GBMember Xamurai

    Seems like a bug in VS Mac. It seems that when adding the files from disk VS Mac will add them without the Xamarin.Forms metadata. You can see the in the properties window that there is no custom tool set. Reloading the solution fixes the problem. Either VS Mac should add the correct metadata or they should be added without that metadata and the .csproj should reflect that. In the second case then I suspect that would break the nesting since the DependentUpon would be set to an empty element.

    I have opened a bug on github for this problem - https://github.com/mono/monodevelop/issues/7038

  • JamesLaveryJamesLavery GBBeta, University ✭✭✭✭✭

    @mattward - great. Glad I'm not going mad, and that we've found something which can hopefully be fixed!

Sign In or Register to comment.