The new NuGet version fixes lots of problems (e.g. transitive dependency capabilities, dependency resolution at build time, single packages repository cache, etc.).
However I could only test it with the ASP.NET vNext and UWP projects.
Will these new features also be available for "legacy" projects (e.g. full .NET 4.5/4.6 projects, WPF, etc.)?
As of 8/19/2015, it seems that the new features are not supported for "legacy" projects but may be added later. According to the NuGet documentation:
project.json is mandatory for UWP apps and ASP.NET 5 apps, is
optional for PCLs, and currently is not fully supported on other
project systems.
and
Starting from Visual Studio 2015, several project types are utilizing
this technology, with more to follow in the future.
1.Universal Windows Platform managed apps (UWP).
2.Portable class libraries (PCL).
3.ASP.NET 5 applications.
Related
I am building a simple library with TeamCity and Octopack because we want this library to be shared with multiple other projects.
I am building it successfully and the .nupkg file has the following internal format.
./{DLLName}.dll
./{DLLName}.pdb
These libraries are made to compile to .NET Framework 4.0 due to needing to be compatible with legacy applications. The projects definitely are set to compile as .NET Framework 4.0.
I believe the problem is that packages are supposed to be build with a format like below.
lib/{DLLName}.dll
lib/{DLLName}.pdb
How do i make octopack put the contents in a lib folder like that?
OctoPack is not designed for that purpose (packaging libraries). It is for packaging applications and other distributables for use with automated deployment tools (primarily Octopus Deploy). Octopus chose the NuGet package format due to the the ease of distribution through existing NuGet feeds and protocols, a convenience. It does however not follow the official conventions when packing, to allow a library to be used by a project
From the documentation:
OctoPack should only be installed on projects that you are going to deploy - that means the console application projects, Windows Service projects, and ASP.NET web applications. Unit tests, class libraries, and other supporting projects wouldn't be selected.
I suggest you use another method, such as this one
I have PCL Library and I want to add it to standard (.net 4.6) C# console application. Everything is fine as long as I don't use any PCL specific classes inside the library. And if I do, I get an error "unsupported PCL profile". This error is not googlable. But the same library works fine in UWP application. I am searching for a solution or official explanation why I can't use PCL in non UWP application.
Yes you can. PCL is basically intersection of available API's across different platforms. The disadvantage is that the more target platforms you choose the smaller is the intersection:
Another disadvantage of PCL is that it generates separate assembly for each platform.
That's why Microsoft comes with .NET Standard - a replacement of PCL that uses different approach.
Think about .NET Standard as an interface, that defines set of API's. Then the platforms like .NET Framework, .NET Core, Xamarin.iOS, Xamarin.Android will implement the .NET Standard.
interface NetStandard1_0 {
}
interface NetStandard1_1 : NetStandard1_0{
}
interface NetStandard1_2 : NetStandard1_1{
}
net46: NetStandard1_6 {
}
dnxcode46: NetStandard1_6 {
}
As a result, you won't target specific platforms, but a version of .NET Standard instead. When your library targets .NET Standard, it can be used in any platform that implements the .NET Standards. Another advantage is you wont need separate assemblies for different platforms anymore. There will be single assembly that runs just everywhere.
However, I recommend you to wait until April 2017 when .NET Standrard 2.0 should be released. Microsoft promised that all platforms (.NET Framework, .NET Core, Xamarin.iOS, Xamarin.Android) will support this version of .NET Standard and it will have official support in Visual Studio. Also, Visual Studio projects using project.json will be converted to .csproj, so all Visual Studio projects will use the same format and it will solve a lot of compatibility issues. Cleanning of the mess that appeared in .NET last years was absolutelly necessary
Sure you can.
Just add .NET 4.6 to selected platforms:
It's appears at time when you create PCL.
More information here:
Cross-Platform Development with the Portable Class Library
Or you can change platforms in existing PCL. Just go to properties page and you will see:
Here is a good blog post about how to call UWP API from desktop App:
How to call UWP APIs from a desktop VB/C# app
To be clear, I follow the MVVM pattern, and I want to structure my project such that I can share my model code between a UWP app and a standard WPF app. The code I want to share has no UI. I don't relish the thought of finding new tools to replace the ones that I've been using for years that take care of certain tasks like logging, connecting to a document oriented database, etc.
I attempted to start writing a UWP wrapper around some code I already have and reference the model project directly. Visual Studio refused to let that happen, showing me an error message that says "Unable to add a reference to project 'ACK.Model'". The same thing happened when I attempted to put the model in a Universal Library and reference it from a WPF app. I'm not trying to share WPF code. Just the model layer that has no reference to UI libraries.
This is a scary proposition, because it means that if I want to do anything substantial I have to choose to either jump 100% to UWP or stay 100% WPF. NewtonSoft.JSON might have a universal distribution (ASP.NET MVC), but what about ElasticSearch.NET, and other tools needed to make important apps?
I found where the "Portable Class Library" project type was hiding. PCLs will allow me to share my code across WPF and Universal apps as that was one of the options. This solves the simple case of the Model part of my code, but I (still) can't use some of the libraries I want. There are still a large number of libraries that I need that do not have PCL available.
About a year later, with the advent of Visual Studio 2017 there is a more complete solution. If you target your libraries to .Net Standard then the library is compatible with both .Net Core apps and the monolithic .Net targeted app. The support for standard .Net libraries and APIs is fairly complete, as is the support for modern C# language features.
The general advice now is this:
Target .Net Standard for all libraries
Target the appropriate platform for your actual application. (UWP or WPF).
NOTE: if your library has to interact with C libraries or applications, you have to take extra care to make sure you load the correct version.
It appears that there is a solution, but it has to be adopted by the whole tool chain you want to use. When Microsoft introduced Windows Store apps in Windows 8, they also introduced a Portable Class Library (PCL). The purpose of the PCL is to share code between different parts of your application.
When you create a PCL in Visual Studio 2015, you can specify the types of APIs you want it to be accessible from:
Universal Apps
Mono
.Net Core 5
.Net 4.6
This of course, limits the APIs available to you but most of the ones you want to use are OK as long as it's not UI related. There are other limitations as well:
Your project can only be edited in Visual Studio 2015 or greater
You don't have access to special directories from the Environment variable (i.e. user Documents directory, etc.)
You can't link to a library designed for only one of your target platforms (i.e. libgit2sharp, etc.)
There's no way to browse the API for this subset--MSDN needs to get on the stick. MSDN has updated much of the API documentation, but it's still difficult to figure out what applies to your PCL
However, you can link any library designed for a single target platform to your PCL. It's not ideal, but it's better than nothing.
The ASP.NET MVC stack has been ported to using PCLs, so you can use NewtonSoft.JSON directly as well as any other of those libraries used by that application. However, there are several libraries that have not been ported.
This arrangement forces you to think about how you want to integrate better. The .Net Core 5 seems to be stable, but support is in it's infancy. The current generation of Universal Apps as of VS 2015 update 1 uses .Net Core 5 directly.
There are several features from Nuget that are not currently supported even though work is under way:
MS Build extensions (major changes to MSBuild and the project.json structure)
Install/uninstall scripts (related to the removal of the concept of install)
Content (related to install/uninstall, but work is in progress on this)
Content transforms (related to lack of install/uninstall)
I wish I had a more complete answer. But this is as far as I got once I discovered the PCL and how it evolved for the current infrastructure.
I'm in the process of creating a game creation toolkit that incorporates version control right off the bat. I want to be able to deploy a game as a Windows 10 app, or as a standard WPF app, but due to the libraries I'm using to integrate version control I need to create the editor as a standard WPF app. I had to be a bit creative in building the shared code and importing the correct libraries.
First, my project hierarchy:
Project.Model (Portable Class Library)
Project.Model.Versioning (standard C# library)
Mvvm.Toolkit (Portable Class Library)
Editor (Standard WPF application)
I want the core PCL to be able to load a project and deserialize the JSON encoded objects. The PCL did have access to System.IO, but surprisingly it is not the same as the one defined in the standard C# library. Here's how I had to fix things:
After adding the package reference to NewtonSoft.JSON, I had to change the target framework in the packages.config file:
<package id="Newtonsoft.Json" version="8.0.2" targetFramework="portable-net452+win81" />
All projects dependent on my Project.Model class had to install the `system.io.filesystem' package from nuget so that the System.IO.FileInfo etc. objects were the same.
While this is definitely not a panacea, it's also not a dead end. I'm sure there are more gotchas, but this will at least help with some of the problems.
a .NET Standard library could be used to share a Model-View-ViewModel architecture between a WPF project and a UWP project.
https://www.syncfusion.com/ebooks/xamarin-forms-succinctly/sharing-code-among-platforms
https://devblogs.microsoft.com/dotnet/announcing-uwp-support-for-net-standard-2-0/
Will (or does) the DNX project support frameworks other than ASP.net (Such as WPF or windows forms)? I'd love to create some Wpf class libraries using the newer json project style (and native NuGet package support), but everything seems to be geared towards Asp.net.
Dnx is only for ASP.NET 5 projects (web, console or library).
It doesn't support WPF.
The project.json/xproj based project model (I would not call it DNX projects) can indeed be used to build nuget class libraries for scenarios beyond ASP.Net and DNX.
If you specify in your project.json a SDK like net451 you can additionally add frameworkassemblies like "PresentationCore" or "PresentationFramework" and then start coding in class files against WPF. So you can create a class library with it (i just tested it). It builds and packages itself to NuGet. That NuGet you can use then in your normal WPF project.
It is important to understand the concept of a SDK when talking about the new .Net Framework things: DNX is a SDK similar to UWP or the .Net Framework (WPF/WinForm). The SDK then specifies which CLR and BCL are used in combination with the features of the SDK. Consequently, this project format does not target the DNX SDK (from the architecture) but any SDK. In the end a class library is IL which has references to DLLs. Support for direct references with normal .csproj is planned (IMHO).
But there are restrictions: The project format is new, not yet well supported and integrated, there is no and maybe never will be a WPF designer etc.
I was writing up the supported platforms for my PCL recently, one of which is other PCLs. I was confused if my library (which targets .NET Framework 4.5 and Windows/Phone 8.1) can be used in .NET Core projects as well.
As I understand it, PCLs allow you to share code across multiple platforms without recompilation, while .NET Core does that as well. The only difference is that .NET Core targets a few more platforms, i.e. OS X and Linux, and is open source.
So essentially, I don't see how .NET Core is any different than Microsoft rebranding the PCL and saying "PAY ATTENTION we're going open source and targeting non-Windows platforms!"
So the bottom line is, are PCLs compatible with .NET Core, and vice versa? What's the difference between them?
There is a beautiful article series about it which solved my questions around it ...
https://oren.codes/2015/06/16/demystifying-pcls-net-core-dnx-and-uwp-redux/
https://oren.codes/2015/07/29/targeting-net-core/
.Net Core has all his libraries (e.g. System.IO) in separate NuGet packages (each of them available for the SDKs DNX, UWP and .Net 4.6). Third party libraries target dnxcore50 (DNX) or uap10.0 (UWP) if they access the platform natively or rely on their features. If they do not access the platform but only rely on other packages, they should target dotnet.
dotnet effectively means: I am compatible with any platform which satisfy my dependencies (your library XYZ "dotnet" which uses System.Reflection dnxcore5+net45 could not be used by a UWP uap10.0 app). This effectively ends the combinatoric nightmare of the platforms. The previous target combination dnxcore5+net45 created an intersection between the platforms libraries and each addition would make the situation even worse. dotnet on the other side does not restrict the library on a target but instead forwards this restriction decision to its dependencies (where suddenly new restrictions like the famous unicorn platform can show up).
Therefore as a library author you can target dotnet if you just need other libraries.
Answering your question:
Your PCL is compatible with .Net Core style environments like DNX and UWP if you add the target dotnet, dnxcore50 or uap10.0 depending on the need of your library (see Owen's article for same basic compatibility with the contract Profile 259).
.Net Core is much more than a set of PCLed libraries. It is a new CLR, a new organized framework (packaged in small parts) and the infrastructure for new .Net SDKs (DNX, UWP, and whatever comes next). The term ".Net Core" targets both, the base class library "CoreFx" and the CLR "CoreCLR". But the real platforms are in reality DNX (by ASP.Net team) and UWP (by Windows team).
All of that answer is my current understanding of the .Net Core library situation. It is work in progress, and like mentioned in the posts, not yet public documented.
NOTE DEC 2016: Be aware, dotnet as the predecessor to netstandard1.x has changed in its concept starting with netstandard2.x (.NET Core 2.0; ~JUN 2017). Beginning with netstandard2.0 there will be one common contract (the netstandard.dll) which all platforms (.NET Core, .NET Framework, Xamarin, Mono, Unity3D) implement. This contract will be extended over time and the platform have to either drop support for the latest standard, throw NotImplementedException or implement it.
My understanding is they both are in concept different.
.NET Portable built upon the .NET Full, .NET Core, Windows Phone,etc, as sort of 'bridging layer'.
It actually has no concrete implementation, consider it a 'Package' of assemblies of the 'Interfaces'(contracts).
The scope of .NET Portable 'Package' is dynamic, depends on what 'Targets' platforms you are going to 'bridge'. It's a intersection of the platforms you target, the more platforms the smaller package.
During runtime, this Portable layer is hooked/adapted to the real implementation of .NET full, .net core or...