How to add a new XAML file to a Xamarin.Forms Portable Class Library with Profile 7

DaspuruDaspuru USMember ✭✭

Hi, following the examples in Xamarin Docs and Xamarin Blog regarding adding Azure Active Directory B2C, I had to change the profile of the Xamarin Forms PCL to 7. After that, the option for creating a new XAML in the Xamarin.Forms PCL library just disappeared. I tried to add manually the files as "Empty Text Files" but the solution doesn't link them even not allowing to inherit the ContentPage Class for the partial xaml.cs.

I know I can go an edit the .csproj in some way but this is a new solution and I will be creating a lot of XAML pages in the next months for the project. Is there a way to fix this?

I am using Visual Studio for Mac, because the project is targeted to .NET Standard and shares code with a .NET Core MVC App via another PCL library.

Thanks.

Best Answers

  • JeremyWhiteleyJeremyWhiteley US ✭✭
    Accepted Answer
    > @mattward said:
    > @JeremyWhiteley - This bug has been fixed but there is no release containing this fix yet available.

    Great! I am glad it's fixed. Hopefully the release will be soon! Thank you for letting me know so fast.

Answers

  • mattwardmattward GBMember Xamurai

    Unable to reproduce this with VS for Mac 7.0 build 2740. Switching to Profile 7, then right clicking the project selecting Add - New File, the New File dialog shows the Xaml file templates in the Forms category.

    The Forms category will not be available if the project does not have any Xamarin.Forms references.

    If your project does have some Xamarin.Forms project references are there any errors in the IDE log? Help - Open Log Directory.

  • DaspuruDaspuru USMember ✭✭

    Hi,

    Thanks, I managed to reproduce the issue in a clean solution. You should create the blank Forms App. Then remove Xamarin.Forms Nuget, make the PCL target .NET Standard 1.1, then add Xamarin.Forms again and change the profile. It is easier if you just edit project.json and paste the following settings, then the options for adding Xamarin.Forms pages disappear:

    {
    "dependencies": {
    "Microsoft.Azure.Mobile": "0.7.0",
    "Microsoft.Azure.Mobile.Analytics": "0.7.0",
    "Microsoft.Azure.Mobile.Crashes": "0.7.0",
    "Microsoft.Identity.Client": "1.0.304142221-alpha",
    "NETStandard.Library": "1.6.1",
    "Xam.Plugin.Media": "2.6.2",
    "Xamarin.Forms": "2.3.4.224"
    },
    "frameworks": {
    "netstandard1.1": {
    "imports": [
    "portable-net45+win8"
    ]
    }
    },
    "runtimes": {}
    }

    Thanks

  • mattwardmattward GBMember Xamurai

    Ah, OK. I see your project is using a project.json file. The problem will be that switching to a project.json file since the references check that the New File dialog uses will not work here since there are no references in the project file. These references are resolved at build time.

    There is a similar bug with the Unit Tests window not detecting any unit tests if you use a project.json file.

  • DaspuruDaspuru USMember ✭✭

    Thanks Matt,

    So, in resume it is a bug and there is no workaround yet?

  • JeremyWhiteleyJeremyWhiteley USMember ✭✭

    Any fix yet? It's been over a month!

  • JeremyWhiteleyJeremyWhiteley USMember ✭✭
    Accepted Answer
    > @mattward said:
    > @JeremyWhiteley - This bug has been fixed but there is no release containing this fix yet available.

    Great! I am glad it's fixed. Hopefully the release will be soon! Thank you for letting me know so fast.
Sign In or Register to comment.