Upgrading Old csproj to New csproj in Visual Studio 2017

The new csproj is lightweight, you don’t have to unload the project to edit the csproj file and you can add package references directly to the csproj file, save it and they will be restored in your assembly automatically. Also, alleviates a lot of pain that’s inherent with Nuget package hell in the old csproj and packages.config style of doing things.

Overall, no reason not to migrate. The way to do it is as follows (for WebJobs and class library type projects):

  • Right click the packages.config and click the option to migrate to the new PackageReferences style. This will move all the package references in your csproj file and get rid of the packages.config file.

migrate to new pr

  • Right click on the project -> Unload Project -> Edit {project-name}.csproj. Change the XML to look like the structure below i.e. remove all but the XML sections shown in the gist below. You’ll need to  keep all your package references:


<Project Sdk="Microsoft.NET.Sdk">
<PackageReference Include="Microsoft.Azure.WebJobs">
<!-- List all your package references here -->
<!--List all your project reference-->
<ProjectReference Include="path\to\proj.csproj">
<Name><!--referenced project name--></Name>
view raw proj.csproj hosted with ❤ by GitHub

  • Save, reload and build the project. You will get a few build errors to do with AssemblyInfo.cs file just open that file and remove these lines:


[assembly: AssemblyTitle("{project name}")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("{project name}")]
[assembly: AssemblyVersion("")]
[assembly: AssemblyFileVersion("")]
view raw remove-lines.cs hosted with ❤ by GitHub

Rebuild! You’ve successfully upgraded the old csproj to the new csproj format with PackageReferences!

Just to confirm, right click the project and you should see “Edit {projectname}.csproj” in the menu which you couldn’t with the old format unless you unloaded the project first.

edit proj

NB: I would recommend doing this in a source controlled environment so that you can revert changes if something does go wrong with this migration. I haven’t tried this migration with all the project types so you might need to do additional research for your needs and then please do let me know.

NB: You might find that in CI environments the project might fail to build because it fails to restore packages using “nuget restore”, to solve this you’re going to have to use “dotnet restore” instead in your build scripts.

One Reply to “Upgrading Old csproj to New csproj in Visual Studio 2017”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.