试图让我的 .net 核心应用程序在 visual studio 代码中达到 运行
Trying to get my .net core application to run in visual studio code
我的 windows 硬盘驱动器最近有点灰尘,最近我正在使用 .net core 1.1 开发 angular 2 .net core 应用程序与 vs 2015。我有一台装有 ubuntu 的计算机,所以我想为什么不下载 vs 代码并克隆我的项目并开始正常工作......好吧,我遇到了问题,希望有人能提供帮助。
我安装了 C# 我安装了 C# 扩展。但这是我得到的错误
Build FAILED.
/home/deshazer/Documents/code/HannaOilGas2/HannaOilAndGas2/project.json(1,1): error MSB4025: The project file could not be loaded. Data at the root level is invalid. Line 1, position 1.
0 Warning(s)
1 Error(s)
Time Elapsed 00:00:00.06
现在我的 project.json 文件看起来像这样
{
"dependencies": {
"Microsoft.NETCore.App": {
"version": "1.1.0",
"type": "platform"
},
"Microsoft.AspNetCore": "1.1.0",
"Microsoft.AspNetCore.Mvc.Core": "1.1.1",
"Microsoft.AspNetCore.AngularServices": "1.0.0-*",
"Microsoft.AspNetCore.Razor.Tools": {
"version": "1.0.0-preview2-final",
"type": "build"
},
"Microsoft.AspNetCore.Diagnostics": "1.1.0",
"Microsoft.AspNetCore.Mvc": "1.1.1",
"Microsoft.AspNetCore.Server.IISIntegration": "1.1.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.1.0",
"Microsoft.AspNetCore.StaticFiles": "1.1.0",
"Microsoft.Extensions.Configuration.CommandLine": "1.1.0",
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.1.0",
"Microsoft.Extensions.Configuration.Json": "1.1.0",
"Microsoft.Extensions.Logging": "1.1.0",
"Microsoft.Extensions.Logging.Console": "1.1.0",
"Microsoft.Extensions.Logging.Debug": "1.1.0",
"Microsoft.Extensions.Options.ConfigurationExtensions": "1.1.0",
"Microsoft.EntityFrameworkCore.SqlServer": "1.1.0",
"Microsoft.EntityFrameworkCore.SqlServer.Design": "1.1.0",
"Microsoft.EntityFrameworkCore.Tools": "1.1.0-preview4-final"
},
"tools": {
"Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final",
"Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final",
"Microsoft.DotNet.Watcher.Tools": "1.0.0-preview2-final"
},
"frameworks": {
"netcoreapp1.1": {
"imports": [
"dotnet5.6",
"portable-net45+win8"
]
}
},
"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true
},
"runtimeOptions": {
"configProperties": {
"System.GC.Server": true
}
},
"publishOptions": {
"include": [
"appsettings.json",
"ClientApp/dist",
"node_modules",
"Views",
"web.config",
"wwwroot"
]
},
"scripts": {
"prepublish": [
"npm install",
"node node_modules/webpack/bin/webpack.js --config webpack.config.vendor.js --env.prod",
"node node_modules/webpack/bin/webpack.js --env.prod"
],
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
},
"tooling": {
"defaultNamespace": "HannaOilAndGas2"
}
}
我也发现我的模型和控制器有问题,我使用的是网络 api 谁能在 vs 代码中帮助我解决这个问题?
using System;
using System.Collections.Generic;
namespace HannaOilAndGas2.Data
{
public partial class MainView
{
public int RecId { get; set; }
public string Location { get; set; }
public double? SpotFlowRate { get; set; }
public double? PreviousDayVolume { get; set; }
public double? LinePressure { get; set; }
public double? DifferentialPressure { get; set; }
public double? Temperature { get; set; }
public double? BatteryVoltage { get; set; }
public double? Fcp { get; set; }
public double? Ftp { get; set; }
public DateTime? Timestamp { get; set; }
public string LastCommunicationMethod { get; set; }
public string MeterId { get; set; }
public string ImportMethod { get; set; }
public int HannaDeviceId { get; set; }
}
}
说找不到类型系统,要求我将 int 放入方法中,嗯。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using HannaOilAndGas2.Data;
// For more information on enabling Web API for empty projects, visit http://go.microsoft.com/fwlink/?LinkID=397860
namespace HannaOilAndGas2.Controllers
{
[Produces("application/json")]
[Route("api/mainview")]
public class MainViewApi : Controller
{
private readonly ScadaContext _context;
public MainViewApi(ScadaContext context)
{
_context = context;
}
// GET: api/values
[HttpGet]
[Route("allmainview")] //front end - done
public IEnumerable<MainView> GetAllMainView()
{
return _context.Main_View.Where(x => !x.MeterId.StartsWith("HOGC"));
}
[HttpGet]
[Route("allwinccuview")] //front end - done
public IEnumerable<MainView> GetAllWinccuView()
{
return _context.Main_View.Where(x => x.ImportMethod == "WINCCU" );
}
[HttpGet]
[Route("allmanualview")] //front end - done
public IEnumerable<MainView> GetAllManualView()
{
return _context.Main_View.Where(x => x.ImportMethod == "SPREADSHEET");
}
[HttpGet]
[Route("allservicestarview")] //front end - done
public IEnumerable<MainView> GetAllServiceStarView()
{
return _context.Main_View.Where(x => x.ImportMethod == "SERVICESTAR-POLL");
}
[Route("allcanadaview")] //front end - done
public IEnumerable<MainView> GetAllCanadaView()
{
return _context.Main_View.Where(x => x.MeterId.StartsWith("HOGC"));
}
// GET api/values/5
[HttpGet("{id}")]
public IEnumerable<MainView> GetMainViewDataById(int id)
{
return _context.Main_View.Where(x => x.RecId == id);
}
// POST api/values
[HttpPost]
public void Post([FromBody]string value)
{
}
// PUT api/values/5
[HttpPut("{id}")]
public void Put(int id, [FromBody]string value)
{
}
// DELETE api/values/5
[HttpDelete("{id}")]
public void Delete(int id)
{
}
}
}
这是说我的 project.json 中的预定义类型系统字符串未定义或再次导入 netcoreapp1.1 请提供任何帮助。
Project.json 改回 .csproj。我建议您使用
迁移您的项目
dotnet 迁移命令
在 CLI 中,就像您在 Linux 中 运行 一样。
我的 windows 硬盘驱动器最近有点灰尘,最近我正在使用 .net core 1.1 开发 angular 2 .net core 应用程序与 vs 2015。我有一台装有 ubuntu 的计算机,所以我想为什么不下载 vs 代码并克隆我的项目并开始正常工作......好吧,我遇到了问题,希望有人能提供帮助。
我安装了 C# 我安装了 C# 扩展。但这是我得到的错误
Build FAILED. /home/deshazer/Documents/code/HannaOilGas2/HannaOilAndGas2/project.json(1,1): error MSB4025: The project file could not be loaded. Data at the root level is invalid. Line 1, position 1. 0 Warning(s) 1 Error(s) Time Elapsed 00:00:00.06
现在我的 project.json 文件看起来像这样
{
"dependencies": {
"Microsoft.NETCore.App": {
"version": "1.1.0",
"type": "platform"
},
"Microsoft.AspNetCore": "1.1.0",
"Microsoft.AspNetCore.Mvc.Core": "1.1.1",
"Microsoft.AspNetCore.AngularServices": "1.0.0-*",
"Microsoft.AspNetCore.Razor.Tools": {
"version": "1.0.0-preview2-final",
"type": "build"
},
"Microsoft.AspNetCore.Diagnostics": "1.1.0",
"Microsoft.AspNetCore.Mvc": "1.1.1",
"Microsoft.AspNetCore.Server.IISIntegration": "1.1.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.1.0",
"Microsoft.AspNetCore.StaticFiles": "1.1.0",
"Microsoft.Extensions.Configuration.CommandLine": "1.1.0",
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.1.0",
"Microsoft.Extensions.Configuration.Json": "1.1.0",
"Microsoft.Extensions.Logging": "1.1.0",
"Microsoft.Extensions.Logging.Console": "1.1.0",
"Microsoft.Extensions.Logging.Debug": "1.1.0",
"Microsoft.Extensions.Options.ConfigurationExtensions": "1.1.0",
"Microsoft.EntityFrameworkCore.SqlServer": "1.1.0",
"Microsoft.EntityFrameworkCore.SqlServer.Design": "1.1.0",
"Microsoft.EntityFrameworkCore.Tools": "1.1.0-preview4-final"
},
"tools": {
"Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final",
"Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final",
"Microsoft.DotNet.Watcher.Tools": "1.0.0-preview2-final"
},
"frameworks": {
"netcoreapp1.1": {
"imports": [
"dotnet5.6",
"portable-net45+win8"
]
}
},
"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true
},
"runtimeOptions": {
"configProperties": {
"System.GC.Server": true
}
},
"publishOptions": {
"include": [
"appsettings.json",
"ClientApp/dist",
"node_modules",
"Views",
"web.config",
"wwwroot"
]
},
"scripts": {
"prepublish": [
"npm install",
"node node_modules/webpack/bin/webpack.js --config webpack.config.vendor.js --env.prod",
"node node_modules/webpack/bin/webpack.js --env.prod"
],
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
},
"tooling": {
"defaultNamespace": "HannaOilAndGas2"
}
}
我也发现我的模型和控制器有问题,我使用的是网络 api 谁能在 vs 代码中帮助我解决这个问题?
using System;
using System.Collections.Generic;
namespace HannaOilAndGas2.Data
{
public partial class MainView
{
public int RecId { get; set; }
public string Location { get; set; }
public double? SpotFlowRate { get; set; }
public double? PreviousDayVolume { get; set; }
public double? LinePressure { get; set; }
public double? DifferentialPressure { get; set; }
public double? Temperature { get; set; }
public double? BatteryVoltage { get; set; }
public double? Fcp { get; set; }
public double? Ftp { get; set; }
public DateTime? Timestamp { get; set; }
public string LastCommunicationMethod { get; set; }
public string MeterId { get; set; }
public string ImportMethod { get; set; }
public int HannaDeviceId { get; set; }
}
}
说找不到类型系统,要求我将 int 放入方法中,嗯。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using HannaOilAndGas2.Data;
// For more information on enabling Web API for empty projects, visit http://go.microsoft.com/fwlink/?LinkID=397860
namespace HannaOilAndGas2.Controllers
{
[Produces("application/json")]
[Route("api/mainview")]
public class MainViewApi : Controller
{
private readonly ScadaContext _context;
public MainViewApi(ScadaContext context)
{
_context = context;
}
// GET: api/values
[HttpGet]
[Route("allmainview")] //front end - done
public IEnumerable<MainView> GetAllMainView()
{
return _context.Main_View.Where(x => !x.MeterId.StartsWith("HOGC"));
}
[HttpGet]
[Route("allwinccuview")] //front end - done
public IEnumerable<MainView> GetAllWinccuView()
{
return _context.Main_View.Where(x => x.ImportMethod == "WINCCU" );
}
[HttpGet]
[Route("allmanualview")] //front end - done
public IEnumerable<MainView> GetAllManualView()
{
return _context.Main_View.Where(x => x.ImportMethod == "SPREADSHEET");
}
[HttpGet]
[Route("allservicestarview")] //front end - done
public IEnumerable<MainView> GetAllServiceStarView()
{
return _context.Main_View.Where(x => x.ImportMethod == "SERVICESTAR-POLL");
}
[Route("allcanadaview")] //front end - done
public IEnumerable<MainView> GetAllCanadaView()
{
return _context.Main_View.Where(x => x.MeterId.StartsWith("HOGC"));
}
// GET api/values/5
[HttpGet("{id}")]
public IEnumerable<MainView> GetMainViewDataById(int id)
{
return _context.Main_View.Where(x => x.RecId == id);
}
// POST api/values
[HttpPost]
public void Post([FromBody]string value)
{
}
// PUT api/values/5
[HttpPut("{id}")]
public void Put(int id, [FromBody]string value)
{
}
// DELETE api/values/5
[HttpDelete("{id}")]
public void Delete(int id)
{
}
}
}
这是说我的 project.json 中的预定义类型系统字符串未定义或再次导入 netcoreapp1.1 请提供任何帮助。
Project.json 改回 .csproj。我建议您使用
迁移您的项目dotnet 迁移命令
在 CLI 中,就像您在 Linux 中 运行 一样。