Submodules in .NET

by on under programming
3 minute read

Using Git Submodules in .NET

You will need to migrate all the projects involved away from packages.config to project.json. See below project type specific instructions.

You will need to clone the Git Submodules into a folder. I use the solutions root folder /lib. See: core/src/develop/lib/

You can then reference the Submodule project relative to the solution. Ensure it’s relative path otherwise it wont work on other peoples machines.

How to migrate package.config to project.json

If I recall correctly this is due to NuGet deps were previously restored per a project instead of per a solution.

Official wiki page but a more manual approach: Converting a csproj from package.config to project.json

A related blog post on the topic: Oren Codes - Project.json all the things

Powershell script to automate it: nugetprojectjson

Example command for a .NET Framework 4.6.1 project: .\create_project_json.ps1 -r -f net461

A couple fixes and issues I found for you to be aware of:

nugetprojectjson/issues/5

nugetprojectjson/pull/4

Project types

.NET Standard 2.0 class library and ASP.NET Framework 4.6.1 MVC

This assumes a .NET Standard 2.0 class library with Project.csproj package references and a ASP.NET Framework 4.6.1 MVC project with package.config.

  1. Migrate the ASP.NET Framework project to project.json.
  2. If you plan to consume a .NET Standard 2.0 class library in a ASP.NET Framework 4.6.1 project you will need Visual Studio 2017 or newer.
  3. If it’s a MVC project you will need to run the project, stop it and then double click the binding redirect warning to update the Web.Config automatically with the correct bindings.

.NET Standard 2.0 class library and .NET Framework 4.6.1 Windows Form

Could not load file or assembly

This assumes a .NET Standard 2.0 class library with Project.csproj package references and a .NET Framework 4.6.1 Windows Form project with package.config.

  1. Migrate the .NET Framework project to project.json.
  2. If you plan to consume a .NET Standard 2.0 class library in a .NET Framework 4.6.1 project you will need Visual Studio 2017 or newer.
  3. If the Windows Form project has no NuGet packages you can manually create the project.json with the following contents:
{
	"dependencies": {

	},
	"frameworks": {
	  "net461": {}
	},
	  "runtimes":  {
		  "win-anycpu": {},
		  "win": {}
	  }
  }

.NET Framework 4.6.1 class library and ASP.NET Framework 4.6.1 MVC

This assumes two .NET Framework 4.6.1 projects with package.config.

  1. Migrate both projects to project.json.
  2. You wont need binding redirects unless you have a version mismatch in NuGet deps.

.NET Framework 4.6.1 PackageReference format

.NET Standard 2.0 class library and ASP.NET Core 2.0+ MVC

This assumes a .NET Standard 2.0 class library and a ASP.NET Core 2.0+ MVC project with Project.csproj.

Works fine without all this mumbo jumbo. See example: Core/Core.csproj

Framework compatibility

Some of these issues are around .NET Framework 4.6.1 not being “fully” compatible with .NET Standard 2.0. Despite the .NET implementation support suggesting otherwise. .NET Framework 4.7.2 is supposed to be fully supported.

See point 2 under the .NET implementation support table for more information.

This is more to do with the binding redirects and versions of dependencies as .NET Framework 4.6.1 actually “implements .NET Standard 1.4”. However it will support up to .NET Standard 2.0 with binding redirects.

Azure DevOps/VSTS CI

You will need to ensure clone Submodules is part of the continuous integration pipeline.

Potential roadblocks

comments powered by Disqus