I'm experimenting with Visual Studio 2015 RC, specifically looking at switching to the new ASP.NET 5 framework, project structure and the new DNX that runs ASP.NET 5 applications.
My employer has many existing solutions targeting .NET Framework 4.5.2. In our existing Visual Studio solutions we might have the following projects:
[Solution] Sample.sln [Folder] src [Project] ClassLibrary.csproj [Project] WindowsService.csproj [Project] WebApplication.csproj [Folder] test [Project] ClassLibrary.UnitTests.csproj ...
In this scenario, ClassLibrary.csproj
is a C# class library containing shared code. It is a dependency of / referenced by both WindowsService.csproj
and WebApplication.csproj
.
We aren't specifically trying to target .NET Core, dnxcore50
. At this stage we are happy targeting .NET Framework, dnx451
. However we are absolutely trying to leverage the new features of ASP.NET 5 and associated project structure.
Below are some options I've thought of but both have issues.
When we replace the WebApplication.csproj
project above with a new ASP.NET 5 DNX project WebApplication-dnx
then we can still reference the ClassLibrary.csproj
from both this new DNX project and the existing WindowsService.csproj
project. However some issues arise:
This approach means any changes to code in ClassLibrary.csproj
need a rebuild to be visible in the running WebApplication-dnx
. This isn't surprising but means we do not get full compile-from-source benefits for WebApplication-dnx
.
We cannot easily target other frameworks, e.g. dnxcore50
. As above, this isn't specifically a goal at this stage.
If we replace ClassLibrary.csproj
with a DNX class library project^ ClassLibrary-dnx
then the problems in option 1 do not apply. This approach would seem to be more in-keeping with the way the .NET runtime and associated technologies such as ASP.NET will be packaged moving forward.
However I cannot find a way to reference ClassLibrary-dnx
from WindowsService.csproj
. If this approach is viable I imagine the solution has something to do with the project level-option for Produce outputs on build
and then referencing the .nupkg
or perhaps even the .dll
that is produced during the build. However, I cannot see a clean way of achieving this via the tooling.
^ DNX class library projects are called Class Library (Package)
in VS 2015 RC. This project type was previously called ASP.NET Class Library
in the CTPs.
Based on the information above I'm looking for:
Some feedback to my scenario options and issues.
Suggestions for other options I have not thought of.
Perhaps an indication of which approach should be used moving forward.
json” file in ASP.NET 5 ASP.NET Core 1.0. This new file the way to define your dependencies, managing your runtime frameworks, compilation settings, adding scripts to execute at different events (Prebuild, Postbuild etc.)
json file used by NuGet is a subset of that found in ASP.NET Core projects. In ASP.NET Core project. json is used for project metadata, compilation information, and dependencies. When used in other project systems, those three things are split into separate files and project.
Right click your project and select "Edit ProjectName. csproj" to view the file.
Take a look at what EntityFramework does.
They target 3 TFMs: net45, .NETPortable,Version=v4.5,Profile=Profile7, frameworkAssemblies and they have both csproj and xproj in the same folder.
Basically, for each project you have two project files.
However I cannot find a way to reference ClassLibrary-dnx from WindowsService.csproj.
Unfortunately, that's not possible, yet. You can only reference csproj from xproj, not the other way around. You have two alternatives: (1) have both xproj and csproj like EF does or (2) reference the NuGet package from csproj.
If you want to do alternative (2) then you can set the output of the xproj to a folder and add that as a NuGet feed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With