Debugging Xamarin Open Source Frameworks: Xamarin.Forms

JGoldbergerJGoldberger USMember, Forum Administrator, Xamarin Team, University Xamurai

We just published our blog on Debugging Xamarin Open Source Frameworks: Xamarin.Forms. Please post any questions or comments here.

Posts

  • TomislavEricTomislavEric USMember

    Hi Jon, thanks for the post! Can you please tell me how to build the nuget package with a mac? Can't run a batch file with my unix based system :)

    After clonging the repo and changing the branch to 2.5.0 the .nuspec file looks good (without any win80, winRT and so on).
    I also tried to run nuget pack .nuspec/Xamarin.Forms.nuspec but without luck.

  • JGoldbergerJGoldberger USMember, Forum Administrator, Xamarin Team, University Xamurai
    edited March 2018

    Good question., and honestly I am not sure.

    The full command from the .bat script is:

    NuGet.exe pack Xamarin.Forms.nuspec -properties configuration=debug;platform=anycpu -Version 9.9.%DEBUG_VERSION%
    

    so perhaps try

    nuget pack Xamarin.Forms.nuspec -properties configuration=debug;platform=iPhoneSimulator -Version <_versionNumber_>
    

    Another thing is you may need to edit the .nuspec file to use forward slashes instead of backslashes. Or such is indicated in this thread.

    Also when building Xamarin.Forms on the Mac, you should build with the iPhoneSimulator platform (so that the UWP stuff is ignored)

    There is another trick you can do so that you do not have to build a NuGet package. You can use an existing (released and downloaded) nuget package and then just replace the assemblies (Xamarin.Forms.Core, etc.) and mdb/pdb files that are in the existing NuGet package with the assemblies and mdb/pdb from your build. Look in the lib folder in the NuGet package for the platform folders, i.e. MonoAndroid10, as to where to copy the assembly and mdb/pdb files from your build:

    You need to copy the assembly and mdb/pdb files for all of the platforms you are using.

  • ctaggartctaggart USMember

    Hi Jon, this is a perfect example of where enabling source link support for Xamarin Forms and the Visual Studio Mac debugger would make it make it much simpler for developers to contribute to debugging. github.com/ctaggart/sourcelink

  • GregMercerGregMercer USUniversity ✭✭

    Hi Jon,

    Thanks very much for the blog post. It has been a big help. I am running into one thing, which I was hoping you might know what I've missed.

    I've cloned the 2.5.0 branch, and made a nupkg file.

    I created a new project using Share Project code sharing. Ran using the current Xamarin.Form official released package on iPhone simulator. All ran fine. Then I removed the official Xamarin.Form package and replaced it with the new nupkg file I had just created.

    Yet when I go to rebuild the project I get the following error:
    "App.xaml.cs(9,13,9,32): error CS0103: The name 'InitializeComponent' does not exist in the current context"

    Any ideas on what would help? Thanks.

  • JGoldbergerJGoldberger USMember, Forum Administrator, Xamarin Team, University Xamurai

    @GregMercer

    First I would ry to clean the project, even deleting the bin and obj folders in each project folder. I would also close and re-open the solution.

    Let me know if that helps.

  • ryborgryborg USMember ✭✭

    Although it is possible to build Xamarin.Forms on a Mac via the command line, doing so would not build the UWP platform assemblies for Xamarin.Forms. As such, we’ll be using a Windows PC with Visual Studio 2017 for this post.

    I am interested in how this is done on a mac. I would love to be able to step though Xamarin.Forms on a mac, getting to that point seems totally mysterious to me, though. My dev machine is a mac, so that's all I have on hand. I don't have a Windows machine readily available.

    I work with iOS and Android only, so any platforms other than those aren't a concern. Where to begin?

  • ryborgryborg USMember ✭✭
    edited November 2018

    I was able to get this working on my Mac. Here was my approach:

    • Build the project

      msbuild Xamarin.Forms.sln /p:Platform=iPhoneSimulator
      
    • Edit .nuspec/Xamarin.Forms.nuspec

    • Search for lines with uap and remove all the lines/xml nodes referencing uap.
    • Build the nuget package

      cd ./nuspec
      nuget pack Xamarin.Forms.nuspec -properties "configuration=debug;platform=iPhoneSimulator" -Version 9.9.0
      
    • Copy nuget package to a local folder

    • Add local folder as a nuget package source
    • Add newly compiled version to project
    • Finally goto Visual Studio > Preferences > Debugger and disable the Debug project code only; do not step into framework code option.
  • DamianMehersDamianMehers CHBeta ✭✭

    @ryborg said:
    I was able to get this working on my Mac. Here was my approach:

    • Build the project

      msbuild Xamarin.Forms.sln /p:Platform=iPhoneSimulator
      
    • Edit .nuspec/Xamarin.Forms.nuspec

    • Search for lines with uap and remove all the lines/xml nodes referencing uap.
    • Build the nuget package

      cd ./nuspec
      nuget pack Xamarin.Forms.nuspec -properties "configuration=debug;platform=iPhoneSimulator" -Version 9.9.0
      
    • Copy nuget package to a local folder

    • Add local folder as a nuget package source
    • Add newly compiled version to project
    • Finally goto Visual Studio > Preferences > Debugger and disable the Debug project code only; do not step into framework code option.

    Fantasic - got this working, thanks!. One other small thing is that for some reason the debug symbols are not packaged for the Mac platform, so you'll need to edit the .nuspec to include the debug files as per the other platforms if you want to debug Xamarin Forms Mac.

  • batmacibatmaci DEMember ✭✭✭✭✭

    @JGoldberger in your article you suggest to fork instead of clone directly. Is there any advantage of forking if we want to contribute? because just cloning could be more beneficial in order to get updates by others and if want to switch between branches like today 3.5 or 4.0 beta branches.

  • JGoldbergerJGoldberger USMember, Forum Administrator, Xamarin Team, University Xamurai

    @batmaci

    It really is up to you. I like forking so I have my own separate repo. That does, however, make it a bit more difficult to get updates from the main repository, but it can be done. See these docs:
    Update fork from master using command line: https://help.github.com/articles/syncing-a-fork/
    Update fork from master using github.com in browser: https://github.com/KirstieJane/STEMMRoleModels/wiki/Syncing-your-fork-to-the-original-repository-via-the-browser

    However it does seem in your scenario that a clone might be best.

  • batmacibatmaci DEMember ✭✭✭✭✭

    @JGoldberger getting updates seems to be working fine if you care only master branch because merge is only done by a single branch. it is cumbersome to sync each available branches.
    on the other hand i was trying other option mentioned here . it seems to be working for android but I am not able to step into UWP application which is more important for me because i plan to do more forking for uwp. Do you know if any special set up or settings required for uwp?

  • JGoldbergerJGoldberger USMember, Forum Administrator, Xamarin Team, University Xamurai

    That's the first I saw of Shane's post and that (seemingly easier) method of stepping into the Forms source code. So, no, I have no idea how to make that work for UWP.

    @ShaneNeuville ^^

  • batmacibatmaci DEMember ✭✭✭✭✭
    edited February 5

    @JGoldberger when i try to run .create-nuget.bat all on Windows machine. it returns me errors as. Do you know why?

    'NuGet.exe' is not recognized as an internal or external command,
    operable program or batch file.
    'msbuild' is not recognized as an internal or external command,
    operable program or batch file.
    'msbuild' is not recognized as an internal or external command,
    operable program or batch file.
    'NuGet.exe' is not recognized as an internal or external command,
    operable program or batch file.
    

    EDIT: msbuild not found: just fixed it by using VS Command prompt
    Nuget.exe not found: I had to download nuget.exe and copied into the main folder and change the line in the script
    set NUGET_EXE=C:\Xamarin.Forms\NuGet.exe. Packing works now :)

  • JGoldbergerJGoldberger USMember, Forum Administrator, Xamarin Team, University Xamurai
    edited February 5

    LOL

    I see you figured it out. Yes, Nuget.exe has to be where the script can find it, or you set the path to it in the script as you did.

    I not too long ago updated the blog post to cover this issue. The Forms team had changed the .create-nuget.bat since I first wrote the blog post.

  • batmacibatmaci DEMember ✭✭✭✭✭
    edited February 5

    Something is wrong with creating nuget. although I have created a nuget package successfully and replaced the official one. It doesnt recognize xamarin.forms.Init function. It returns other errors. I cleaned all bin, obj and nuget cache folders. restarted VS2017

  • JGoldbergerJGoldberger USMember, Forum Administrator, Xamarin Team, University Xamurai

    It looks like the references are corrupted. Look in the package you created (you can change the .nupkg extension to .zip and unzip), and then in the libs folder of the package look in each of the platform folders and check the file size for the .dlls. They should be larger than a few bytes. Check this thread to see if it helps you move forward: https://forums.xamarin.com/discussion/144408/xamarin-forms-built-from-source-missing-uwp-windowspage

  • batmacibatmaci DEMember ✭✭✭✭✭

    One of the error i get is 9.9.5\lib\MonoAndroid90\FormsViewGroup.dll ---> System.BadImageFormatException: Format of the executable (.exe) or library (.dll)

    when i compare official nuget folder FormsViewGroup.dll and the one I created. official one has bigger size than mine. why does it create smaller?

  • JGoldbergerJGoldberger USMember, Forum Administrator, Xamarin Team, University Xamurai

    I got similar errors when the .dlls were corrupted by this line in the .create-nuget.bat when argument "all" was not added when running the script:

    echo foo > Xamarin.Forms.Platform.Android.FormsViewGroup\bin\debug\FormsViewGroup.dll
    

    That literally overwrites the FormsViewGroup.dll with the text "foo". The script runs all of the echo foo > ... lines unconditionally. So I think you will need to rebuild that .dll. If the size of your .dll is 1K, then this might be the issue.

  • batmacibatmaci DEMember ✭✭✭✭✭

    I tried edited part of your blog post but unfortunately, alternative script also creates same as .create-nuget.bat all.

  • JGoldbergerJGoldberger USMember, Forum Administrator, Xamarin Team, University Xamurai

    Not sure what is going on. I might suggest avoiding that script, cleaning and rebuilding Xamarin.Forms from scratch and then using the nuget.exe pack ... command to make your package.

  • batmacibatmaci DEMember ✭✭✭✭✭

    hi @JGoldberger, i could finally fix the problem with the latest 3.5 source code. it works fine with android and ios but Uwp is not working. i can see that nugetpackage has pdb files included. do you have any idea what could be the reason?

  • JGoldbergerJGoldberger USMember, Forum Administrator, Xamarin Team, University Xamurai

    Not without more information. "Not working" is not a clear problem description. :-)

    Is the problem in the building of the UWP Forms assembly? IOW does the build succeed without issue?

    Is the problem in the packaging? Are you getting valid Xamarin.Forms.Platform.UAP.dll in the nuget package?

  • RedRaRedRa Member ✭✭✭

    @JGoldberger Thanks for your post !!

    I cannot debug Xamarin.Forms NuGet Package
    I add "My" Xamarin.Forms NuGet Package to my project and open Grid file from sources where located Xamarin.Forms and then put in some function break point, Visual Studio stops when I call this function, but does not open Grid file and show location where breakpoint hits

    I tried to add -Symbols but seems like it did not help (:

  • JGoldbergerJGoldberger USMember, Forum Administrator, Xamarin Team, University Xamurai

    @RedRa

    Hmm, not sure why that is happening. Are you doing this all on the same machine? IN other words, are you using "your" nuget package on the asme machine where you built "your" nuget package?

    There is another option to be able to step into Xamarin.Forms source code without having to build your own nuget package. See this blog post for info on doing that instead if you like: https://shaneneuville.com/xamarin/forms/debugging/2018/02/01/debug-tips.html

Sign In or Register to comment.