VS 2017 .NET Core BinaryFormatter

2019-02-16 20:35发布

Is with VS 2017 released in the .NET Core tools BinaryFormatter included? When I create a .NET Core console application I cannot find BinaryFormatter. There are many Nuget packages but which one is the right one to get a working BinaryFormatter with .NET Core?

By the way it is a bit awkward to create with a released Visual Studio a project which does not compile. I need to start a cmd shell where my .NET Core console application resides and do a

dotnet restore

to get it to compile. Did I miss a VS command in the references menu?

Edit1

Using Install-Package BinaryFormatter gives me an exception

PM> Install-Package BinaryFormatter
Restoring packages for d:\source\vc17\NetCoreApp\ConsoleApp1\ConsoleApp2\ConsoleApp2.csproj...
Install-Package : Package BinaryFormatter 1.0.2 is not compatible with netcoreapp1.1 (.NETCoreApp,Version=v1.1). Package BinaryFormatter 1.0.2 supports:
  - dnx451 (DNX,Version=v4.5.1)
  - dnxcore50 (DNXCore,Version=v5.0)
At line:1 char:1
+ Install-Package BinaryFormatter
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Install-Package], Exception
    + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand

Install-Package : One or more packages are incompatible with .NETCoreApp,Version=v1.1.
At line:1 char:1
+ Install-Package BinaryFormatter
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Install-Package], Exception
    + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand

Install-Package : Package restore failed. Rolling back package changes for 'ConsoleApp2'.
At line:1 char:1
+ Install-Package BinaryFormatter
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Install-Package], Exception
    + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand

1条回答
做个烂人
2楼-- · 2019-02-16 21:00

EDIT

Thanks to @ClockEndGooner for pointing out, that People who are using .Net-Core 2.1 or later there is a Binary Formatter Located in:

System.Runtime.Serialization.Formatters.Binary

Here is a nuget package for that it says it supports core as well:

Install-Package BinaryFormatter

I'm not sure if this contains what you need but is also the System.Runtime.Serialization.Formatters

Install-Package System.Runtime.Serialization.Formatters

These packages work with .Net-Core 1.0 in order for them to work with a 1.1 enviroment you will require cross comiplation you can reference this Core Issue

查看更多
登录 后发表回答