dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.27k stars 4.73k forks source link

Referencing .NET Core project to the regular .NET csproj #16383

Closed zemstaspamera closed 4 years ago

zemstaspamera commented 8 years ago

Hello,

Is there any way to reference project created with .NET Core (dnxcore50 and dnx451) to regular C# project, for example WPF? I found a proposition.which probably allows me to do what I want. However, is referencing a "net46" framework a good solution? I have not seen that before.

I'm asking because I preparing a strategy for API for corporate services based on Desktop apps and I would like to make it available also on Linux.

Thanks for help.

weshaggard commented 8 years ago

@Pilchie I assume this is a question for your team.

@zemstaspamera we do hope to enable this scenario but with the current VS tools it is a little rough.

manu-st commented 8 years ago

I've build a way to do that. Check out: https://github.com/manu-silicon/corefxref. It will enable you to compile against the relatively recent version of CoreFX reference assemblies. However I'm not sure if you will be able to mix this with WPF as WPF may rely on APIs not yet present in CoreFX.

Pilchie commented 8 years ago

I think there are a couple of different things here that are being conflated:

Hope this helps. @davidfowl - anything I've missed?

rolfik commented 8 years ago

@Pilchie,

The ability to reference a project.json/xproj project from a .csproj project.

It is possible now via nuget package created from xproj, but only when You do not have the xproj and csproj project folder in the same parent folder or solution, because then "project reference to xproj" wins over "nuget package reference to xproj" and it cannot be overriden by let us say type attribute of the dependency in project.json. Or is there a way to do it somehow?

When will be the next release of .NET Core tools (CLI?) released?

jnm2 commented 8 years ago

How soon until I can reference an xproj project in the same solution as a full framework csproj? Is that going to be part of the xproj -> csproj msbuild work?

It's a big holdup to even getting started with .NET Core. Xproj is the only option at the moment because the core library needs multi-targeting. (ECDsaCng has been available on full framework since .NET 3.5 but isn't available until netstandard1.4, and the top-level GUI client is required to be net452 which restricts me to netstandard1.2 so I can't use a single-target netstandard1.4 PCL csproj. If I understand correctly, the only option for ECDsaCng is to target netstandard1.4 and net45 separately.)

Pilchie commented 8 years ago

Tagging @davkean and @srivatsn.

srivatsn commented 8 years ago

Yes, once .NET Core projects are csproj based then you should be able to reference them from a full framework csproj. That work is being tracked by https://github.com/dotnet/roslyn-project-system/issues/282

mellinoe commented 8 years ago

We recently added this document which describes how you can set up cspoj's now to accomplish what you want. Keep in mind that it's fairly manual and easy to mess up right now.

jnm2 commented 8 years ago

@mellinoe Slightly confused- which project gets this edit? The multi-target xproj class library or the full framework csproj winforms app? Surely I'm not modifying the full framework csproj to use dotnet.exe? But if I'm modifying the multi-target DLL xproj by changing it to a csproj and following this document, why would I add a StartAction?

mellinoe commented 8 years ago

For a class library, use the instructions at the top of the document. The StartAction stuff would just be for Exe projects, so not applicable in your case. And, yes, you wouldn't be modifying your .NET framework project, except potentially to make it use project.json for dependencies.

jnm2 commented 8 years ago

The instructions at the top of the document don't seem to address the scenario where I need to target both netstandard1.4 and net45. They instruct me to create a new PSL csproj, but I don't see where it gets converted from single-target to multi-target. Like I said, I need ECDsaCng in the class library whether I'm using it with a core app or a full framework 4.5.2 app. Am I wrong in thinking that a single target project is not an option and that the class library needs to be xproj for multi-target? In which case I can't use csproj?

mellinoe commented 8 years ago

In your case, you would probably end up having two csproj's, one for each configuration (net452, netstandard1.4). You could share common includes in a shared build file as well, if you wanted. Technically you could combine them into one file, but it would probably quickly get messy and would require lots of manual fiddling with project configurations.

This probably isn't buying you much in your particular case since you need to specifically target net452.

jnm2 commented 8 years ago

I don't mind hacking a csproj and eschewing tooling, but maintaining two project file lists is unappealing. I'll wait then until I'm able to target both netstandard1.4 and net45 in a single csproj.

gulbanana commented 8 years ago

is that feature (multi-targeting from a csproj with tooling support) planned? seems a bit different to the original question of csproj->xproj references. of course it'd be great to have both.

jnm2 commented 8 years ago

Well xproj is going away entirely, right? And multi-targeting isn't, so it would end up in csproj, right?

srivatsn commented 8 years ago

Yes it's tracked here - https://github.com/dotnet/roslyn-project-system/issues/190

gulbanana commented 8 years ago

excellent

karelz commented 8 years ago

Closing, it does not look like there is anything left for corefx discussion. Work is tracked in Roslyn.