如何在 vscode 中将 `System.Web.Extensions` 程序集添加到 .net core 项目 [英] How to add `System.Web.Extensions` assembly to .net core project in vscode

查看:82
本文介绍了如何在 vscode 中将 `System.Web.Extensions` 程序集添加到 .net core 项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经安装了对 vscode 的 c# 支持(版本是 1.15.0)并通过 dotnet new console 创建了一个 HelloWorld 项目.

I have installed c# support for vscode(version is 1.15.0) and created a HelloWorld project via dotnet new console.

现在在 Program.cs 中,我想使用依赖于 System.Web.Extensions 程序集的 JavaScriptSerializer 类.我输入 using 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 core 的一部分,但是有没有办法将程序集添加到项目中?

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.

推荐答案

System.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 core 项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆