Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not working with projects targeting net47 #45

Closed
Abdruggi opened this issue Aug 10, 2017 · 10 comments
Closed

Not working with projects targeting net47 #45

Abdruggi opened this issue Aug 10, 2017 · 10 comments

Comments

@Abdruggi
Copy link
Contributor

The Migration Tools are not working with net47 projects. I am ending up getting following exception:

Unhandled Exception: Microsoft.DotNet.Cli.Utils.CommandUnknownException: No executable found matching command "dotnet-ef"
at Microsoft.DotNet.Cli.Utils.ProjectDependenciesCommandFactory.FindProjectDependencyCommands(String commandName, IEnumerable1 commandArgs, String configuration, NuGetFramework framework, String outputPath, String buildBasePath, String projectDirectory) at Microsoft.DotNet.Cli.Utils.ProjectDependenciesCommandFactory.Create(String commandName, IEnumerable1 args, NuGetFramework framework, String configuration)
at Migrator.EF6.Tools.Program.Dispatch(String[] args)
at Migrator.EF6.Tools.Program.Main(String[] args)

Anyone having the same issue and a working fix?

@mrahhal
Copy link
Owner

mrahhal commented Aug 10, 2017

Haven't tested it on net47. Will try to test it soon.

@Abdruggi
Copy link
Contributor Author

I think the problem is the GetTargetFramework method(ProjectReader.cs). The method should be more flexible. i will submit a pr.

@Abdruggi
Copy link
Contributor Author

Abdruggi commented Aug 10, 2017

I would recommend something like this:

public static NuGetFramework GetTargetFramework(string frameworkString)
{
	if (frameworkString.StartsWith("netcoreapp", StringComparison.OrdinalIgnoreCase))
	{
		var versionText = frameworkString.Substring("netcoreapp".Length);

		return new NuGetFramework(".NETCoreApp", FrameworkNameHelpers.GetVersion(versionText));
	}
	else if (frameworkString.StartsWith("netstandard", StringComparison.OrdinalIgnoreCase))
	{
		var versionText = frameworkString.Substring("netstandard".Length);

		return new NuGetFramework(".NETStandard", FrameworkNameHelpers.GetVersion(versionText));
	}
	else if (frameworkString.StartsWith("net", StringComparison.OrdinalIgnoreCase))
	{
		var versionText = frameworkString.Substring("net".Length);

		return new NuGetFramework(".NETFramework", FrameworkNameHelpers.GetVersion(versionText));
	}

	return new NuGetFramework(frameworkString);
}

@mrahhal
Copy link
Owner

mrahhal commented Aug 10, 2017

@Abdruggi Agreed. Would you like to submit a PR?

@Abdruggi
Copy link
Contributor Author

Abdruggi commented Aug 11, 2017

@mrahhal I will submit the PR during the weekend,

@Abdruggi
Copy link
Contributor Author

Abdruggi commented Aug 13, 2017

@mrahhal Pull request is ready for review (#46). Whereas the new code is perfectly running for the sample app (target framework net47) there are still some issues with the current project i am working on. but i don't no whether they are related to my project or the migrator. Need some more time for testing.

@Abdruggi
Copy link
Contributor Author

Abdruggi commented Aug 14, 2017

@mrahhal It took me longer than expected, but i was able to track down my problem. Out of the box it is not possible to generate migrations for net4X projects referencing netstandard projects. The migrator or better the reflection part is looking for System.Runtime and some other libraries in version 4.1.0.0 but netstandard1.6 references them in version 4.1.1.0. It's a well known problem.

The fix is pretty simple. Just create a file with the content below and the name "dotnet-ef.exe.config" in the net4X project and set copy to output to true.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.1.0.0" newVersion="4.1.1.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.1.0.0" newVersion="4.1.1.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Runtime.InteropServices" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.1.0.0" newVersion="4.1.1.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Linq.Expressions" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.1.0.0" newVersion="4.1.1.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

@mrahhal
Copy link
Owner

mrahhal commented Aug 14, 2017

Well, this is a recurring problem it seems. And binding redirects are always involved.

But since you've investigated, can you expand on this:

Out of the box it is not possible to generate migrations for net4X projects referencing netstandard projects.

I didn't understand, I've always used this with net4x projects that referenced netstandard projects. Oh, but I guess the aspnet packages multi target both netstandard and net4x.

So are you saying the problem occurs when the migrations project has a reference to a pure netstandard package?

@nphmuller also mentioned a similar fix at #37.

@Abdruggi
Copy link
Contributor Author

Exactly, my EF project (net47) references some infrastructure projects (pure netstandard1.6). Because of that, the mentioned libraries are to "new". 4.3 (4.1.1.0) instead of 4.1 (4.1.0.0).

I would probably be a good idea to mention that in the readme.

The necessary Migration project file (.csproj) changes:

  <ItemGroup>
    <None Remove="dotnet-ef.exe.config" />
  </ItemGroup>
  <ItemGroup>
    <Content Include="dotnet-ef.exe.config">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
  </ItemGroup>

@mrahhal
Copy link
Owner

mrahhal commented Aug 15, 2017

Right now I'm recommending that people use migrations on a pure "Models" project, and reference that from their web app. But I should also mention this in the readme for people who really want to use other options. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants