Carolyn Van Slyck

Upgrade to .NET vNext

While I have read informal comments from the .NET developers that vNext is intended for new development, I really wanted to upgrade BytesForHealth to .NET vNext (.NET 5).

Here are some of the steps I took to upgrade:

  1. Install Visual Studio 2015 Preview.
  2. Install KVM.
    iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/aspnet/Home/master/kvminstall.ps1')"
  3. Verify that you are using at least the beta of KPM: kpm --version should return 1.0.0-beta1-10662. If not run kvm upgrade to get the latest KRE and then kvm use 1.0.0-beta1 -x86 -r CLR -p to set it as the active version.
  4. Open Visual Studio and create a ASP.NET Class Library (vnext) project. Take that kproj file and copy it into your each of your project directories, name it after the project and if you like overkill, update the project's guid to match the original in the csproj. Now edit your solution file and tweak the project reference to use the kproj file instead of the csproj file and update the project type guids from FAE04EC0-301F-11D3-BF4B-00C04F79EFBC to 8BB2217D-0F2D-49D1-97BC-3654ED321F3B.
  5. Rename packages.config to project.json. Add { "dependencies": { at the top and using some creative find/replace, alter your packages xml to the new json format.
    Before
    <?xml version="1.0" encoding="utf-8"?>
    <packages>
        <package id="AutoMapper" version="2.2.1" targetFramework="net45" />
        <package id="Microsoft.AspNet.Mvc" version="4.0.20710.0" targetFramework="net45" />
    </packages>
    

    After
    {
      "dependencies": {
        "AutoMapper": "2.2.1",
        "Microsoft.AspNet.Mvc": "4.0.20710.0"
      }
    }
  6. Using your original csproj, find .NET Framework references (e.g. System.Web, or just look for anything without a packages hintpath), and add them to the frameworkassemblies section in project.json.
    {
      "dependencies": {
        "AutoMapper": "2.2.1",
          "Microsoft.AspNet.Mvc": "4.0.20710.0"
      },
      "frameworks": {
        "net45": {
          "frameworkAssemblies": {
            "System.Web": "4.0.0.0"
          }
        }
      }
    }
    
  7. Using your original csproj file, find project references and add them as dependencies in your project.json file. The name of the dependency will be the name of the project. For example if ProjectA references ProjectB, then it should have the following line in its project.json dependencies section "ProjectB": "".
  8. Delete your old csproj files.
  9. If all of your source code is in a single directory and at the same level, i.e. not nested, then you can skip this next step. Otherwise you will need to add a global.json to the root of your solution. In order for projects to reference each other when they are not in the same directory, add a hint path for where the projects can be found.
    {
      "sources": ["Src", "Src/ReallyAwesomeStuff", "RandomDir"]
    }
    </ol> You should now be able to build your solution using Visual Studio. You can build individual projects by first running `kpm restore` in the soluiton directory, then by running `kpm build` from within each project directory. If it builds with Visual Studio but not via the command line, review step 3 and make sure you are using the latest version of the KRE.