我正在尝试创建一个类库,它将包含WebAPI(使用ASP.NET 5)和消费UWP App的公共对象(主要是DTO).但是,我还没有想出如何创建类库,以便可以从其他项目中引用它.
到目前为止
我尝试过:首先,我尝试了一个类库(包),它可以在Web下找到.可以从ASP.NET项目中引用这种类型的库而不会出现问题,但是当尝试从UWP项目引用它时,我收到以下消息:
A reference to 'ClassLibrary1' could not be added.
Run Code Online (Sandbox Code Playgroud)
接下来,我尝试了一个类库(Windows Universal),它可以在Windows> Universal下找到.这可以很容易地从UWP项目中引用,但是当尝试从ASP.NET引用它时,我得到:
The following projects are not supported as references :
- The project ClassLibrary2 has a target framework that is incompatible or has version higher than the current project and cannot be referenced.
Run Code Online (Sandbox Code Playgroud)
那么:我如何创建一个可以在ASP.NET 5项目和 UWP项目中使用的类库?
我有一个新的ASP.net 5 dnx类库,我用于实体框架.我需要针对EF 6,因为我需要的一些功能不在EF 7中.
首先,EF工具(如启用迁移)不存在.我添加了一个旧的样式类库并安装了EF 6,现在命令就在那里.
当我运行启用迁移时,我收到此错误:
PM>启用 - 迁移
异常调用 "SetData的" 与 "2" 的参数(一个或多个):在装配"类型 'Microsoft.VisualStudio.ProjectSystem.VS.Implementation.Package.Automation.OAProject'"Microsoft.VisualStudio.ProjectSystem.VS.Implementation,版本= 14.1. 0.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a'未标记为可序列化." 在d:\项目\卤面\ FMS \代码\电流\ FMSSupport\FMSSupport \包\ EntityFramework.6.1.3\TOOLS\EntityFramework.psm1:720字符:5 + $ domain.SetData( 'startUpProject',$ startUpProject)+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo:NotSpecified:(:) [],MethodInvocationException + FullyQualifiedErrorId:SerializationException System.NullReferenceException:未将对象引用设置为对象的实例.在System.Data.Entity.Migrations.Extensions.ProjectExtensions.GetProjectTypes(工程项目的Int32 shellVersion)在System.Data.Entity.Migrations.Extensions.ProjectExtensions.IsWebProject(工程项目)在System.Data.Entity.Migrations.MigrationsDomainCommand. GetFacade(字符串configurationTypeName,布尔useContextWorkingDirectory)在System.Data.Entity.Migrations.EnableMigrationsCommand.FindContextToEnable(字符串contextTypeName)在System.Data.Entity.Migrations.EnableMigrationsCommand.<> c__DisplayClass2.<构造函数> b__0()在System.Data .Entity.Migrations.MigrationsDomainCommand.Execute(Action command)对象引用未设置为对象的实例.
我尝试了不同的启用迁移选项,例如指定启动项目或contextTypeName.
有任何想法吗?
在标准中,.csproj
您可以进入属性并设置默认命名空间.如何在.xproj
项目中实现project.json
?
我正在使用ASP.NET Core RC2,当我运行dotnet run
我的应用程序时总是在"生产"中运行.我无法将其更改为"开发".
我有以下launchSettings.json
文件:
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:26088/",
"sslPort": 0
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"MVCCoreRc2App": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我不确定为什么dotnet
在设置时在"生产"中运行应用程序"ASPNETCORE_ENVIRONMENT": "Development"
.
这在ASP.NET Core RC1中有效.我错过了什么?
我刚刚将一个正在运行的RC2 Web应用程序转换为RTM,我在IIS上发布了一些问题.
我找到的所有示例都基于NetCoreApp1.0应用程序.由于某些要求,我们仅限于"net46".
这是project.json
{
"version": "1.0.0-*",
"dependencies": {
"Domain": "1.0.0-*",
"Microsoft.AspNetCore.Authentication": "1.0.0",
"Microsoft.AspNetCore.Authentication.Cookies": "1.0.0",
"Microsoft.AspNetCore.Authentication.Facebook": "1.0.0",
"Microsoft.AspNetCore.DataProtection.SystemWeb": "1.0.0",
"Microsoft.AspNetCore.Diagnostics": "1.0.0",
"Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore": "1.0.0",
"Microsoft.AspNetCore.Http.Extensions": "1.0.0",
"Microsoft.AspNetCore.Localization": "1.0.0",
"Microsoft.AspNetCore.Mvc": "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.EnvironmentVariables": "1.0.0",
"Microsoft.Extensions.Configuration.Json": "1.0.0",
"Microsoft.Extensions.Logging.Console": "1.0.0",
"Microsoft.Extensions.Logging.Debug": "1.0.0",
"Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
"PublicLib": "1.0.0-*",
"PublicLib.Imaging": "1.0.0-*",
"PublicLib.Interfaces": "1.0.0-*",
"Storage": "1.0.0-*"
},
"tools": {
"Microsoft.AspNetCore.Server.IISIntegration.Tools": {
"version": "1.0.0-preview2-final"
}
},
"frameworks": {
"net46": {
}
},
"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true
},
"publishOptions": {
"include": [
"wwwroot", …
Run Code Online (Sandbox Code Playgroud) 背景:最近我从"旧"世界切换到新的project.json世界,因为新的总是更好;)目前3个项目中有2个可以使用"dotnet"目标框架名字对象,另一个需要完整的.NET框架(net46).
我还将我的测试项目切换到新的project.json世界,但我无法进行任何测试.构建是绿色的,但没有找到测试.
我阅读了这个文档并包含了xunit.runner.dnx,但问题是它不是"dnx"项目 - 它依赖于"dotnet"或"net46"而且当前的运行者似乎没有找到试验.
该项目可在GitHub上获得.
xunit.runner.dnx包中的错误:
错误项目Sloader.Config.Tests中的依赖项xunit.runner.dnx 2.1.0-beta5-build169不支持框架.NETPlatform,Version = v5.0.Sloader.Config.Tests C:\ Users\Robert\Documents\GitHub\Sloader\tests\Sloader.Config.Tests\project.json 20 IntelliSense
这是目前不支持还是我错过了什么?谢谢!
我已经更新了一个类库project.json
来定位netstandard1.3
和net64
.
有了这个改变:
$ dotnet restore
log : Restoring packages
warn : Dependency specified was NETStandard.Library (>= 1.3.0) but ended up with
NETStandard.Library 1.6.0.
Run Code Online (Sandbox Code Playgroud)
我正在发布一个库,真的需要目标netstandard1.3
/ net46
.
如何诊断为何使用更高版本?
我正在创建一个可重用的库,它针对几个平台(.NET 4.0,.NET 4.5,.NETStandard 1.0和.NETStandard 1.3).此项目的.NET 4.5版本包含.NET 4.0版本下不可用的一些功能.
引用此库项目的单元测试项目有一个单一的目标平台,即NET 4.5.1.该测试项目显然包含一些代码,用于测试核心库的.NET 4.5特定功能.
但不幸的是,测试项目没有编译,因为Visual Studio似乎引用了.NETStandard 1.0版本,显然不包含此功能.
为了演示我的问题,我将其简化为以下两个项目:
核心库:
{
"version": "1.0.0-*",
"frameworks": {
"netstandard1.0": {
"dependencies": {
"NETStandard.Library": "1.6.0"
}
},
"net40": {},
"net45": {}
}
}
Run Code Online (Sandbox Code Playgroud)
代码文件:
namespace CoreLibrary
{
#if NETSTANDARD1_0
public class ClassNetStandard { }
#endif
#if NET40
public class ClassNet40 { }
#endif
#if NET45
public class ClassNet45 { }
#endif
}
Run Code Online (Sandbox Code Playgroud)
测试库:
{
"version": "1.0.0-*",
"dependencies": {
"CoreLibrary": { "target": "project" }
},
"frameworks": {
"net451": {}
} …
Run Code Online (Sandbox Code Playgroud) (问题小标题:资源不支持.netstandard 1.3
或者我的项目文件是否搞砸了?)
我刚刚在Visual Studio 2015 Update 3中创建了一个示例可移植类库,并添加了一个示例资源文件.最初,该文件project.json
如下所示:
{
"supports": {
"net46.app": {},
"uwp.10.0.app": {},
"dnxcore50.app": {}
},
"dependencies": {
"Microsoft.NETCore": "5.0.0",
"Microsoft.NETCore.Portable.Compatibility": "1.0.0"
},
"frameworks": {
"dotnet": {
"imports": "portable-net452+win81"
}
}
}
Run Code Online (Sandbox Code Playgroud)
好的:没有编译错误!
之后,我使用项目属性进行定位.NETStandard 1.3
.
现在project.json
看起来像这样:
{
"supports": {},
"dependencies": {
"Microsoft.NETCore.Portable.Compatibility": "1.0.1",
"NETStandard.Library": "1.6.0"
},
"frameworks": {
"netstandard1.3": {}
}
}
Run Code Online (Sandbox Code Playgroud)
现在我得到以下构建错误 - 这意味着基本上EmbeddedRessource
不支持构建操作:
我真的不是专家project.json
,但对我来说,事情看起来不一致 - 我不知道问题出在哪里.
project.json
:如果我支持net46
,为什么要导入net452
?project.json …