从RC1

时间:2016-09-14 07:31:40

标签: asp.net-web-api asp.net-core

我们正在构建一个新的WebApi。我们开始在暑假前使用.Net Core Rc1 - 现在,.Net Core为1.0我想更新。

但是我遇到了一些问题 - 如果我能解决的话,我无法弄明白?

挑战在于我需要引用一些.Net 4.5.1 x86程序集。

这意味着我需要使用允许使用.Net 4.5.1的名字 - 如果我需要这两个世界,据我所知 - 只有netstandard16可用。 (https://docs.microsoft.com/da-dk/dotnet/articles/standard/library

但后来我遇到了.Net 4.6.3(或上面链接中的vNext)尚未出现的问题。

如果我参考netstandard15 - 那么AspNetCore库就无法工作。

如果我引用netstandard16 - 那么我会收到以下错误

error : Can not find runtime target for framework '.NETStandard,Version=v1.6' compatible with one of the target runtimes: 'win10-x64, win81-x64, win8-x64, win7-x64'. Possible causes:
error : 1. The project has not been restored or restore failed - run `dotnet restore`
error : 2. The project does not list one of 'win10-x64, win81-x64, win8-x64, win7-x64' in the 'runtimes' section.
error : 3. You may be trying to publish a library, which is not supported. Use `dotnet pack` to distribute libraries.

是否可以使用当前可用位来执行以下操作

  • 在.Net 4.5中为x86编译了一个业务层(需要重用它 - 遗产很棒)
  • 创建Asp.Net核心网站
  • 在网站中引用业务层 - 只进行编码

有人能帮助我吗?

编辑:project.json(两个版本)

来自RC1

{
  "version": "1.0.0-*",
  "compilationOptions": {
    "emitEntryPoint": true
  },

  "dependencies": {
    "AutoMapper": "4.2.1",
    "Microsoft.AspNet.IISPlatformHandler": "1.0.0-rc1-final",
    "Microsoft.AspNet.Mvc": "6.0.0-rc1-final",
    "Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final",
    "Microsoft.AspNet.StaticFiles": "1.0.0-rc1-final",
    "Microsoft.Extensions.Configuration.FileProviderExtensions": "1.0.0-rc1-final",
    "Microsoft.Extensions.Configuration.Json": "1.0.0-rc1-final",
    "Microsoft.Extensions.Logging": "1.0.0-rc1-final",
    "Microsoft.Extensions.Logging.Console": "1.0.0-rc1-final",
    "Microsoft.Extensions.Logging.Debug": "1.0.0-rc1-final",
    "Swashbuckle.SwaggerUi": "6.0.0-rc1-final",
    "Swashbuckle.SwaggerGen": "6.0.0-rc1-final"
  },

  "commands": {
    "web": "Microsoft.AspNet.Server.Kestrel"
  },

  "frameworks": {
    "dnx451": {
      "dependencies": {
        "BaseClasses": "1.0.0-*",
        "DatabaseAccessCS": "1.0.0-*",
        "BusinessLogic": "1.0.0-*",
        "StandardFunctionsCS": "1.0.0-*"
      },
      "frameworkAssemblies": {
        "System.configuration": "4.0.0.0"
      }
    }
  },

  "exclude": [
    "wwwroot",
    "node_modules"
  ],
  "publishExclude": [
    "**.user",
    "**.vspscc"
  ]
}

最终1.0的尝试最接近工作

{
  "version": "1.0.0-*",
  "buildOptions": {
    "debugType": "portable",
    "emitEntryPoint": true
  },
  "dependencies": {
    "AutoMapper": "5.1.1",
    "Microsoft.AspNetCore.Mvc": "1.0.0",
    "Microsoft.AspNetCore.Mvc.Core": "1.0.0",
    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
    "Microsoft.AspNetCore.StaticFiles": "1.0.0",
    "Microsoft.Extensions.Configuration.Json": "1.0.0",
    "Microsoft.Extensions.Logging": "1.0.0",
    "Microsoft.Extensions.Logging.Console": "1.0.0",
    "Microsoft.Extensions.Logging.Debug": "1.0.0",
    "Swashbuckle.SwaggerGen": "6.0.0-beta902",
    "Swashbuckle.SwaggerUi": "6.0.0-beta902"
  },
  "frameworks": {
    "netstandard16": {
      "dependencies": {
        "BaseClasses": {
          "target": "project"
        },
        "DatabaseAccessCS": {
          "target": "project"
        },
        "BusinessLogic": {
          "target": "project"
        },
        "StandardFunctionsCS": {
          "target": "project"
        }
      }
    }
  }
}

有效的最终json

{
  "version": "1.0.0-*",
  "buildOptions": {
    "debugType": "portable",
    "emitEntryPoint": true,
    "platform": "x86"
  },
  "runtimes": {
    "win":  ["win7-x86", "win8-x86", "win10-x86"]
  },
  "dependencies": {
    "AutoMapper": "5.1.1",
    "LogiholdBusinessObjects": "5.5.0",
    "Microsoft.AspNetCore.Mvc": "1.0.0",
    "Microsoft.AspNetCore.Mvc.Core": "1.0.0",
    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
    "Microsoft.AspNetCore.StaticFiles": "1.0.0",
    "Microsoft.Extensions.Configuration.Json": "1.0.0",
    "Microsoft.Extensions.Logging": "1.0.0",
    "Microsoft.Extensions.Logging.Console": "1.0.0",
    "Microsoft.Extensions.Logging.Debug": "1.0.0",
    "Swashbuckle.SwaggerGen": "6.0.0-beta902",
    "Swashbuckle.SwaggerUi": "6.0.0-beta902"
  },
  "frameworks": {
    "net451": {
      "frameworkAssemblies": {
        "System.Configuration": "4.0.0.0"
      }
    }
  }
}

1 个答案:

答案 0 :(得分:1)

如果您需要.NET Core应用程序,则应使用using Excel = Microsoft.Office.Interop.Excel; using VBE = Microsoft.Vbe.Interop.Forms; private static void ExcelOperation(string xlFileName) { var xlApp = new Excel.Application(); var xlWorkbook = xlApp.Workbooks.Open(xlFileName); var xlSheet = xlWorkbook.Worksheets["your_sheet_Name"] as Excel.Worksheet; try { Excel.OLEObjects oleObjects = xlSheet.OLEObjects() as Excel.OLEObjects; foreach (Excel.OLEObject item in oleObjects) { if (item.progID == "Forms.TextBox.1") { VBE.TextBox xlTB = item.Object as VBE.TextBox; Console.WriteLine("Name: " + item.Name); Console.WriteLine("Text: " + xlTB.Text); Console.WriteLine("Value: " + xlTB.get_Value()); Marshal.ReleaseComObject(xlTB); xlTB = null; } else if (item.progID == "Forms.CheckBox.1") { VBE.CheckBox xlCB = item.Object as VBE.CheckBox; Console.WriteLine("checkbox: " + item.Name); Console.WriteLine("Value: " + xlCB.get_Value()); Marshal.ReleaseComObject(xlCB); xlCB = null; } } Marshal.ReleaseComObject(oleObjects); oleObjects = null; } catch(Exception ex) { Console.WriteLine(ex.Message); } Marshal.ReleaseComObject(xlSheet); xlSheet = null; xlWorkbook.Close(); Marshal.ReleaseComObject(xlWorkbook); xlWorkbook = null; Marshal.ReleaseComObject(xlApp); xlApp = null; } 目标框架。您可能无法在.NET Core应用程序中引用.NET 4.5.1库。

您还可以像这样定位桌面(完整).NET Framework:

netcoreapp1.0

现在您可以使用.NET 4.5.1库,但您的应用程序不再在.NET Core运行时上运行。

您也可以定位更高版本的.NET,例如`net461。