Tag: .net core

在VS2017中将依赖程序集包含在NuGet包中

我有一个包含2个项目(NET Core)的解决方案。 第一个项目(库)包含主程序集,另一个项目(库)包含一个包含资源,接口和其他东西的程序集。 主项目引用了第二个项目。 我正在使用Visual Studio 2017.当我从主项目创建NuGet包时,附件组件不包含在包的lib文件夹中。 怎么能实现这一目标? 注意:我不想将附属程序集引用为NuGet包,我希望这个程序集成为主程序包的一部分。

是否真的需要.net core 2 API中的services.AddSingleton

我在.NET Core 2 Web API Controller中访问了appsettings.json,只需添加以下内容: public class MyController : Controller { private readonly IConfiguration appConfig; public MyController(IConfiguration configuration) { appConfig = configuration; } } 在services.AddMvc();之后没有在Startup类ConfigureServices(IServiceCollection服务)中添加以下内容: services.AddSingleton(Configuration); 我的方法有什么缺陷吗? 在.Net Core 2配置部分的官方文档中,没有提及使用’AddSingleton’甚至一次: https ://docs.microsoft.com/en-us/aspnet/core/fundamentals/configuration 也通过搜索我无法找到访问配置的相关内容! https://docs.microsoft.com/en-us/search/index?search=AddSingleton&scope=ASP.NET+Core 下面的链接显示AddSingleton,如同必须的步骤 : 访问控制器类中的appsettings.json值 https://blogs.technet.microsoft.com/dariuszporowski/tip-of-the-week-how-to-access-configuration-from-controller-in-asp-net-core-2-0/

.NETentity framework核心

我已经阅读了过去两年发布的关于EF的几乎所有其他问题。 我没有下载其他软件包的问题,​​它只是不会为我安装的entity framework。 我甚至尝试安装最新版本的Nuget并在我的项目目录中使用它的工具来恢复包 – 后来我将这行添加到我的.csproj中: 首先我尝试了这个命令: dotnet restore 输出这个: C:\Path\To\My\Project>dotnet restore Restore completed in 100.41 ms for C:\Path\To\My\Project\TestNuget.csproj. Restore completed in 68.84 ms for C:\Path\To\My\Project\TestNuget.csproj. 结果如下: > dotnet ef No executable found matching command “dotnet-ef” 所以我尝试了这个(使用最新版本的Nuget截至今天的日期): nuget restore Example.csproj 输出这个: MSBuild auto-detection: using msbuild version ‘15.6.85.37198’ from ‘C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\bin’. Committing restore… […]

dotnet core方法’ValidateOptions’…没有实现

我正在构建一个.NET Core解决方案,它正在构建得很好,但是当我尝试发布它时,会出现以下错误: Method ‘ValidateOptions’ in type ‘Microsoft.CodeAnalysis.CSharp.CSharpCompilationOptions’ from assembly ‘Microsoft.CodeAnalysis.CSharp, Version=2.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35’ does not have an implementation. at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.Create at Microsoft.CodeAnalysis.Razor.CompilationTagHelperFeature.GetDescriptors() at Microsoft.AspNetCore.Razor.Language.DefaultRazorTagHelperBinderPhase.ExecuteCore(RazorCodeDocument codeDocument) at Microsoft.AspNetCore.Razor.Language.DefaultRazorEngine.Process(RazorCodeDocument document) at Microsoft.AspNetCore.Razor.Language.RazorTemplateEngine.GenerateCode(RazorCodeDocument codeDocument) at Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Internal.PrecompileRunCommand.c__DisplayClass23_0.b__0(Int32 i) at System.Threading.Tasks.Parallel.c__DisplayClass19_0`1.b__1(RangeWorker& currentWorker, Int32 timeout, Boolean& replicationDelegateYieldedBeforeCompletion) — End of stack trace from previous location where exception was thrown — at […]

通过.NET Core上的MEF将参数传递给插件构造函数?

我花了几个小时试图弄清楚如何通过MEF(System.Composition)将参数传递给插件构造函数,但都无济于事。 毋庸置疑,相关文档很少,通过源代码看看也无济于事。 这曾经很容易使用CompositionHost.ComposeExportedValue方法,但在.NET Core版本中我似乎无法找到任何有用的东西。 我在下面附上了我的不完整代码,然后是抛出的exception。 在这方面的任何帮助将不胜感激。 谢谢…. using System; using System.Composition; using System.Composition.Hosting; using System.Reflection; namespace MefMe { public interface IPlugin { void Alert(); } [Export(typeof(IPlugin))] public class Plugin : IPlugin { private string code; [ImportingConstructor] public Plugin(string code) { this.code = code; } public void Alert() => Console.WriteLine(code); } class Program { static void […]

validationJWT令牌后访问dotnetcore中间件

我正在使用JWT承载认证,配置如下。 我的问题是在validation令牌之前中间件正在执行。 如何配置中间件以后运行? services.AddAuthentication() .AddCookie(_ => _.SlidingExpiration = true) .AddJwtBearer( _ => { _.Events = new JwtBearerEvents { // THIS CODE EXECUTES AFTER THE MIDDLEWARE???? OnTokenValidated = context => { context.Principal = new ClaimsPrincipal( new ClaimsIdentity(context.Principal.Claims, “local”)); return Task.CompletedTask; } }; _.RequireHttpsMetadata = false; _.SaveToken = false; _.TokenValidationParameters = new TokenValidationParameters() { ValidIssuer = this.Configuration[“Tokens:Issuer”], […]

在OpenIddict中处理请求时发生未处理的exception

所以,我正在尝试使用.net核心1.1实现OpenIddict版本1.0.0-beta2-0580,我收到以下错误: 处理请求时发生未处理的exception 这是基于此: https : //github.com/openiddict/openiddict-core/tree/dev/samples db正确注册数据库,加载设置,一切都在这里工作。 数据库中的表格: __efmigrationshistory , aspnetroleclaims , aspnetroles , aspnetuserclaims , aspnetuserlogins , aspnetuserroles , aspnetusers , aspnetusertokens , basetransaction , openiddictapplications , openiddictauthorizations , openiddictscopes , openiddicttokens 然后我有 堆栈跟踪: InvalidOperationException: The authentication ticket was rejected because the mandatory subject claim was missing. AspNet.Security.OpenIdConnect.Server.OpenIdConnectServerHandler+d__5.MoveNext() System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) Microsoft.AspNetCore.Authentication.AuthenticationHandler+d__66.MoveNext() System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task […]

避免构造函数映射字段

我正在使用带有.NET Core 2.0的AutoMapper 6.2.2及其默认的dependency injection机制来映射模型和DTO。 我在AutoMapper配置中需要DI,因为我必须执行需要一些注入组件的AfterMap 。 问题是,对于某些具有参数匹配某些源成员的构造函数的模型,当我为AutoMapper启用DI时(添加services.AddAutoMapper() ),这些构造函数默认调用并输入数据,然后用EF中断我的操作。 public class UserDTO { public string Name { get; set; } public string Email { get; set; } public ICollection Roles { get; set; } } public class User { public string Name { get; set; } public string Email { get; set; } public ICollection […]

entity framework核心SelectMany然后包括

我似乎无法弄清楚如何在使用SelectMany时让EF Core包含/加载相关对象。 context.MyObject .Where(w => w.Id == Id) .SelectMany(m => m.SubObject) .Include(i => i.AnotherType) 本来会想到类似上面的东西会起作用,但是折叠的SubObject集合使AnotherObject为null并且不包括在内。 一直在寻找几个小时。 任何帮助,将不胜感激。 谢谢

只有1个Main方法的XUnit测试项目:“程序定义了多个入口点。”

我将vNext格式的.NET xUnit测试项目(带有project.json)转换为Visual Studio 2017 RC中的新.csproj格式,并开始收到以下错误。 这个错误的大多数在线答案都说“你有两个主要方法;摆脱一个。” 这似乎是一个明显的解决方案,但这个项目只有一个Main方法。 错误: CS0017程序定义了多个入口点。 使用/ main编译以指定包含入口点的类型。 Project.Name C:\ path \ to \ Program.cs Program.cs中: using XunitProgram = Xunit.Runner.DotNet.Program; namespace My.Namespace.Tests { public static class Program { public static void Main(string[] args) { XunitProgram.Main(args); } } } 老project.json: { “version”: “1.0.0-*”, “testRunner”: “xunit”, “buildOptions”: { “emitEntryPoint”: true, “preserveCompilationContext”: true, “debugType”: “full” […]