如何在vscode中将`System.Web.Extensions`程序集添加到.net核心项目 [英] How to add `System.Web.Extensions` assembly to .net core project in vscode
问题描述
我已经为vscode安装了c#支持(版本为 1.15.0
),并通过 dotnet新控制台$ c $创建了一个HelloWorld项目。 c>。
I have installed c# support for vscode(version is 1.15.0
) and created a HelloWorld project via dotnet new console
.
现在在 Program.cs
中,我想使用 JavaScriptSerializer
类,它依赖于 System.Web.Extensions
程序集。我使用System.Web.Script.Serialization键入了;
并运行了 dotnet restore
,但是vscode无法解决它。错误是,
Now in Program.cs
, I would like to use JavaScriptSerializer
class which depends on System.Web.Extensions
assembly. I typed using System.Web.Script.Serialization;
and run dotnet restore
,but vscode cannot resolve it. The error is,
类型或名称空间名称 Web在名称空间
系统中不存在(您是缺少程序集引用?)
The type or namespace name 'Web' does not exist in the namespace 'System' (are you missing an assembly reference?)
似乎 System.Web
不是.net核心的一部分,但是有什么方法可以将程序集添加到项目中?
It seems that System.Web
is not part of .net core, but is there any way to add the assembly to the project?
我找不到 project.json
文件,因为它是一个csproj项目,因此在其他帖子中也有提及。
I cannot find a project.json
file which is refered in other posts since it is a csproj project.
推荐答案
系统.Web.Extensions
是完整.net框架的一部分。如果要序列化和反序列化对象,可以使用 Newtonsoft.Json
,
System.Web.Extensions
is part of full .net framework . If you want to serialize and deserialize object,You can use Newtonsoft.Json
,
#using Newtonsoft.Json
....
JsonConvert.DeserializeObject(json);
更新
只需从NuGet获取软件包名称和版本号,然后将其添加到.csproj,然后保存即可。
Just get package name and version number from NuGet and add to .csproj then save. You will be prompted to run restore that will import new packages.
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
</ItemGroup>
这篇关于如何在vscode中将`System.Web.Extensions`程序集添加到.net核心项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!