Forum Xamarin Xamarin.Forms

How to Convert Android & iOS Projects to Use .csproj for Package References

DFoulkDFoulk USMember ✭✭✭

Hi guys,

We really like the way the new Xamarin.Forms project templates manage NuGet packages (cleanly). It makes things much easier to manage, thus, we'd like to convert our older apps to this new format. We've successfully converted our PCLs to .NET Standard, but we can't seem to find any information on how to convert the Android & iOS projects to use .csproj for package references.

Can anyone share how to do this? We really don't want to HAVE to take the time (yet) to create new .NET Standard solutions and migrate our code into the new projects. It seems like there should be a way to achieve the same ends the other direction...

Thanks in advance,
-Derek

Best Answer

  • DFoulkDFoulk USMember ✭✭✭
    Accepted Answer

    @EasyEddy - As of Visual Studio 15.7 Preview 3, we now have an easy way to convert these projects:

    Migrate from packages.config to PackageReference

    1. Open a solution containing project using packages.config.
    2. In Solution Explorer, right-click on the References node or the packages.config file and select Migrate packages.config to PackageReference....
    3. The migrator analyzes the project's NuGet package references and attempts to categorize them into Top-level dependencies (NuGet packages that you installed directory) and Transitive dependencies (packages that were installed as dependencies of top-level packages).
    4. (Optional) You may choose to treat a NuGet package classified as a transitive dependency as a top-level dependency by selecting the Top-Level option for the package. This option is automatically set for packages containing assets that do not flow transitively (those in the build, buildCrossTargeting, contentFiles, or analyzers folders) and those marked as a development dependency (developmentDependency = "true").
    5. Review any package compatibility issues.
    6. Select OK to begin the migration.
    7. At the end of the migration, Visual Studio provides a report with a path to the backup, the list of installed packages (top-level dependencies), a list of packages referenced as transitive dependencies, and a list of compatibility issues identified at the start of migration. The report is saved to the backup folder.
    8. Validate that the solution builds and runs. If you encounter problems, file an issue on GitHub.

Answers

  • EasyEddyEasyEddy USMember ✭✭

    Hi,

    we are facing the same problem.
    I wonder if you have found a working solution?
    Maybe you can share it with us.

    Thank you!

    // EDDY

  • DFoulkDFoulk USMember ✭✭✭
    edited April 2018

    Hi @EasyEddy - If I remember correctly...

    1. Make a backup of your solution
    2. Delete packages.config file(s)
    3. Open Tools > Options > NuGet Package Manager > General > Package Management
    4. Set Default package management format to PackageReference
    5. Reinstall NuGet packages (that were in packages.config)

    Don't quote me on this, but I think this was what we tried. Ultimately, our OCD got the better of us and we created a new .NET Standard Xamarin.Forms project and ported our code into it.

    That being said, the above steps are worth a shot as it is much faster than porting an existing project!

    Hope this helps,
    -Derek

  • DFoulkDFoulk USMember ✭✭✭
    Accepted Answer

    @EasyEddy - As of Visual Studio 15.7 Preview 3, we now have an easy way to convert these projects:

    Migrate from packages.config to PackageReference

    1. Open a solution containing project using packages.config.
    2. In Solution Explorer, right-click on the References node or the packages.config file and select Migrate packages.config to PackageReference....
    3. The migrator analyzes the project's NuGet package references and attempts to categorize them into Top-level dependencies (NuGet packages that you installed directory) and Transitive dependencies (packages that were installed as dependencies of top-level packages).
    4. (Optional) You may choose to treat a NuGet package classified as a transitive dependency as a top-level dependency by selecting the Top-Level option for the package. This option is automatically set for packages containing assets that do not flow transitively (those in the build, buildCrossTargeting, contentFiles, or analyzers folders) and those marked as a development dependency (developmentDependency = "true").
    5. Review any package compatibility issues.
    6. Select OK to begin the migration.
    7. At the end of the migration, Visual Studio provides a report with a path to the backup, the list of installed packages (top-level dependencies), a list of packages referenced as transitive dependencies, and a list of compatibility issues identified at the start of migration. The report is saved to the backup folder.
    8. Validate that the solution builds and runs. If you encounter problems, file an issue on GitHub.
  • EasyEddyEasyEddy USMember ✭✭
    @DFoulk thank you very much for this. Wish I had this info earlier. I already re-created those project from scratch ;)
  • DFoulkDFoulk USMember ✭✭✭

    @EasyEddy - For sure! Better late than never though, right? :#

  • batilakbatilak Member ✭✭

    I followed these steps for iOS class lib. All nugets are properly downloaded in global packages however I get build error for Newtonsoft.Json saying "missing assembly" . An hint how to move fwd?

Sign In or Register to comment.