Search code examples
uwpnugetvisual-studio-2019mvvm-light

UWP Install MVVM Light and NuGet


I am working on an UWP Project in Visual Studio 2019 and I wanted to install the MVVM package. The problem is that, as far as I am concerned, since NuGet 3.1 package installations do not allow to create new files and folders because they don't know what to do when those packages are uninstalled. I wanted to know how I could install MVVM Light so that creates these files and completes successfully the installation. Thanks in advance for your answers


Solution

  • The issue is that your uwp project uses PackageReference nuget management format. And the author of MvvmLight nuget package has added content node under the nupkg. It will add the files of the content folder from the nupkg into the main project automatically. However, this works only for packages.config nuget management format.

    enter image description here

    And since your UWPprojects uses PackageReference, it will not work.

    Instead, the author should add contentFiles node into the nupkg file. See one document ,two document and three document.

    Suggestion

    1) You have to contact with the author of the nuget package to add contentFiles into the nuget package.

    2) Since the solution one might take a long time, you could try to use packages.config nuget management format. Although it might have some issues, but it worth trying and it is the fast way to get what you want And please make a backup of your project.

    a) remember any nuget packages and its version you installed on the uwp project.

    b) then, enter the csproj file of the uwp project

    comment or delete these xml nodes:
    
    
      <PropertyGroup>
        <RestoreProjectStyle>PackageReference</RestoreProjectStyle>
      </PropertyGroup>
    

    And delete all PackageReference node like this:

    <ItemGroup>
        <PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
          <Version>6.2.10</Version>
        </PackageReference>
      </ItemGroup>
    ......
    ......
    <ItemGroup>
    

    c) close VS, delete .vs hidden folder under the solution folder, bin and obj folder of the uwp project.

    d) restart VS, enter Tools-->Options-->Nuget Package Manager-->General and change Package Management to Packages.config.

    enter image description here

    e) then install these nuget packages by packages.config.

    Note: please first install Microsoft.NETCore.UniversalWindowsPlatform nuget package version 6.2.8. After that, install the other nuget packages including MvvmLight.

    And you will see the content files from the nuget package:

    enter image description here