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

.NET Core support #197

Merged

Conversation

alexandrnikitin
Copy link
Member

@alexandrnikitin alexandrnikitin commented Aug 21, 2015

This is another option how to get .NET Core support for #192. I prefer this one more comparing to #193. Approach is borrowed from Automapper project.

  • Introduced Class Library (Package) project that targets .Net 4, 4.5 and Core which replaced original NSubstitute.csproj.
  • Introduced TypeExtensions under System.Reflection namespace that handles all work with types.
  • Included Castle.Core assembly compiled against .NET Core based on .NET Core support for Castle.Core castleproject/Core#92
  • Tests projects are unloaded because cannot reference new Class Library (Package) type of project. To solve that we need to introduce separate old type projects like AutoMapper does.

TODO:

  • drop .Net 3.5 support?
  • add old type of class library project and enable tests against it
  • adjust FAKE build scripts to build new type of project
  • add ILMerge for .NET Core project (better to have it in build script)
  • publish alpha version of .NET Core support
  • TBA

Feedback is appreciated.

@alexandrnikitin
Copy link
Member Author

@jasonwilliams200OK Thank you for the PR.

We stuck with combining the .NET 4 build artifacts and the .NET Core ones into one NuGet package. We hope to sort it out soon.

@jirisykora83
Copy link

This is working on classic .NET 4.6 (NSubstitute 1.10) but not in .NET Core.

var httpWebRequest = Substitute.For();

Exception:
Parent does not have a default constructor. The default constructor must be explicitly defined.

at System.Reflection.Emit.TypeBuilder.DefineDefaultConstructorNoLock(MethodAttributes attributes)
at System.Reflection.Emit.TypeBuilder.DefineDefaultConstructor(MethodAttributes attributes)
at System.Reflection.Emit.TypeBuilder.CreateTypeNoLock()
at System.Reflection.Emit.TypeBuilder.CreateTypeInfo()
at Castle.DynamicProxy.Generators.Emitters.AbstractTypeEmitter.CreateType(TypeBuilder type)
at Castle.DynamicProxy.Generators.Emitters.AbstractTypeEmitter.BuildType()
at Castle.DynamicProxy.Generators.ClassProxyGenerator.GenerateType(String name, Type[] interfaces, INamingScope namingScope)
at Castle.DynamicProxy.Generators.BaseProxyGenerator.ObtainProxyType(CacheKey cacheKey, Func`3 factory)
at Castle.DynamicProxy.ProxyGenerator.CreateClassProxy(Type classToProxy, Type[] additionalInterfacesToProxy, ProxyGenerationOptions options, Object[] constructorArguments, IInterceptor[] interceptors)
at NSubstitute.Proxies.CastleDynamicProxy.CastleDynamicProxyFactory.GenerateProxy(ICallRouter callRouter, Type typeToProxy, Type[] additionalInterfaces, Object[] constructorArguments)
at NSubstitute.Core.SubstituteFactory.Create(Type[] typesToProxy, Object[] constructorArguments, SubstituteConfig config)
at NSubstitute.Substitute.For[T](Object[] constructorArguments)

@ghost
Copy link

ghost commented Aug 1, 2016

@alexandrnikitin,

We stuck with combining the .NET 4 build artifacts and the .NET Core ones into one NuGet package. We hope to sort it out soon.

That needs:

  • Adding net45 to project.json and removing csproj and packages.config files.
  • Then running dotnet pack Source/NSubstitute.

I can take care of the first one. When dotnet guys will make cli to msbuild-driven (which is actively work in progress), they will provide a conversion tool from project.json+xproj -> new kind of csproj. At which point we can switch back (like many other projects will). That is nothing more than describing the manifest in XML vs. JSON format.

If you are ok with this, I can do the refactoring. You would only need to run dotnet publish Source/NSubstitute to publish the package to nuget. To test what will land in the package locally, dotnet pack Source/NSubstitute can be used.

@alexandrnikitin
Copy link
Member Author

@jirisykora83 Could you provide more details please. What type do you try to substitute?

@jasonwilliams200OK it isn't that easy unfortunately. I tried to express the current msbuild csproj via project.json sometime ago but failed. We have ILMerge and there were other pitfalls I don't remember of. The best (or only viable option) is to script that procedure via FAKE. There's a working version alexandrnikitin#8 It lacks xml docs for .NET Core and proper nuspec. But it works at least.
You can launch it via NSubstitute>Build Zip mode=Release targets=ALL and observe artifacts in NSubstitute\Output folder.

@jirisykora83
Copy link

@alexandrnikitin Sorry i don't know why it is mis in my post. I try substitute System.Net.HttpWebRequest

alexandrnikitin and others added 10 commits August 2, 2016 22:45
- Added netstandard1.5 as valid target
- Skipped NETCORE_TARGETS for tasks that are currently incompatible
  (such as tests/tests against docs)
- Documented build params in "-T" task
- Hacked around with FAKE target dependencies to try to selectively build
  NET/dotnetcore projects based on targets. Had to add "soft dependencies"
  on Clean and Version to make sure that, if they are being run, they do
  so prior to build. See [1].

[1]: http://fsharp.github.io/FAKE/soft-dependencies.html
@alexandrnikitin alexandrnikitin merged commit ac140ef into nsubstitute:master Aug 6, 2016
dtchepak pushed a commit that referenced this pull request Aug 7, 2016
(DT: Record of Peter's commits got lost while merging #197.
Cherry-picked one of many commits as a marker for these
contributions.)
dtchepak pushed a commit that referenced this pull request Aug 7, 2016
(DT: Record of Peter's commits got lost while merging #197.
Cherry-picked one of many commits as a marker for these
contributions.)
@dtchepak
Copy link
Member

dtchepak commented Aug 7, 2016

Hi everyone,

This is all part of the 2.0.0.0-rc release. (It needs to be RC as we take a dependency on a pre-release Castle.Core.)

Thanks to everyone who participated with feedback and test results. Thanks especially to @alexandrnikitin, without whom this release would not have happened. Also thanks to @jasonwilliams200OK for his valuable contributions to the .net core code and CI builds.

Regards,
David

@alexandrnikitin alexandrnikitin deleted the Issue192_NetCore_Project branch November 2, 2016 20:22
@dougajmcdonald
Copy link

I'm trying to use the 2.0.0.rc or 2.0.1rc via nuget but both of them at the moment give me the following warning regarding Castle.Core:

warning NU1603: Castle.Core 4.0.0-beta001 depends on System.ComponentModel.TypeConverter (>= 4.0.1) but System.ComponentModel.TypeConverter 4.0.1 was not found. An approximate best match of System.ComponentModel.TypeConverter 4.1.0 was resolved

Is this to be expected? or is there a better version / rc to play with?

@alexandrnikitin
Copy link
Member Author

@dougajmcdonald The latest stable version is 3.1.0. It targets .NET Standard 1.3 and has all fixes. Please try to use it.

@dougajmcdonald
Copy link

@alexandrnikitin thanks for the pointer, I misread the dependencies in nuget. Compilation is all happy now

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

Successfully merging this pull request may close these issues.