Search Unity

IL2CPP stripping UWP C# code

Discussion in 'Windows' started by yakumoklesk, Jun 26, 2019.

  1. yakumoklesk

    yakumoklesk

    Joined:
    Dec 12, 2013
    Posts:
    5
    Hi. I am trying to port this code:
    https://github.com/microsoft/Unity-Xaml-Sample
    which is compatible with unity 2017, to unity 2019 wit IL2CPP support. The problem is that there are some methods and internal classes of the MainPage.xaml.cs that get stripped out in the C++ generated code. I am not sure if this is an issue of the C++ generation or the stripping itself. I've marked on top of the file with the attrubte [assembly: Preserve], but even with that it does not work.

    Of course, when trying to compile, it fails.

    Hope anybody can hint me to a solution. Thanks in advance.

    David.
     
  2. yakumoklesk

    yakumoklesk

    Joined:
    Dec 12, 2013
    Posts:
    5
    Well, it seems that IL2CPP was not stripping anything, but creating its own App.xaml and App.xaml.cpp and .h as well as the same for MainPage. So in order more or less to make it work I had to create a partial MainPage class for add the extra methods. The thing is that I have to add manually those files in the visual studio project, and also I have to modify the generated MainPage.xaml.cpp to include the MainPage.extra.xaml.h where I define the extra methods.

    Is there a way to tell Unity in the build process that it should tweak the code or the project generated some way instead of modify it every time the project is built?

    Thanks.
     
  3. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,680
    You can use this:

    https://docs.unity3d.com/ScriptReference/Build.IPostprocessBuildWithReport.html

    Basically, Unity will call that method when the build is complete, and you can use it to modify the build in any way you want. Also, keep in mind that if you're building on top of an existing project, Unity will not overwrite any .cpp, .h, .xaml, .vcxproj or manifest changes you have made, so you can commit those files to source control and just build on top of them from Unity.
     
  4. yakumoklesk

    yakumoklesk

    Joined:
    Dec 12, 2013
    Posts:
    5
    Thank you very much. I've followed many of your answers to different users about interoperation between wpf side and unity side and they have been really useful. Hope I can read more from you.