.net-core

Is it possible to remove the full-paths from .NET assemblies created with dotnet build?

穿精又带淫゛_ 提交于 2021-02-20 19:10:32
问题 The bounty expires in 2 days . Answers to this question are eligible for a +50 reputation bounty. sdgfsdh wants to draw more attention to this question. I build my project with dotnet build , targeting netcoreapp3.1 . The problem is that the assemblies contain the full path to the source-files: /home/runner/my-app/App.fs This means that the hash of the assemblies depends on the directory where the code was built. I want it to only depend on the hash of the source-files and the .NET SDK itself

Does .Net Core support User Secrets per environment?

我怕爱的太早我们不能终老 提交于 2021-02-20 19:08:27
问题 Let's say I have connection string for Development environment specified in appsettings.Development.json and connection string for the Staging environment specified in appsettings.Staging.json All I need to do to switch between Development and Staging is to navigate to Visual Studio Debug tab in project properties and change the value for ASPNETCORE_ENVIRONMENT environment variable. Now, of course I don't want to have connection string in appsettings.*.json for security reasons. So I move it

What is the proper way to handle error CA1416 for .NET core builds?

房东的猫 提交于 2021-02-20 10:16:36
问题 Here is my C# code snippet: if (Environment.IsWindows) { _sessionAddress = GetSessionBusAddressFromSharedMemory(); } ... [System.Runtime.Versioning.SupportedOSPlatform("windows")] private static string GetSessionBusAddressFromSharedMemory() { ... } When I run the build, I get an error: error CA1416: 'GetSessionBusAddressFromSharedMemory()' is supported on 'windows' My logic is to invoke the method only when I am on Windows. How do I turn this warning off when building on Ubuntu? Regards. 回答1:

What is the role of “MaxAutoRenewDuration” in azure service bus?

こ雲淡風輕ζ 提交于 2021-02-20 10:14:58
问题 I'm using Microsoft.Azure.ServiceBus . (doc) I was getting an exception of: The lock supplied is invalid. Either the lock expired, or the message has already been removed from the queue. By the help of these questions: 1, 2, 3, I am able to avoid the Exception by setting the AutoComplete to false and by increment the Azure's queue lock duration to its max (from 30 seconds to 5 minutes). _queueClient.RegisterMessageHandler(ProcessMessagesAsync, new MessageHandlerOptions

Dependency Injection in .NET Core 3.0 for WPF

梦想的初衷 提交于 2021-02-20 05:45:22
问题 I’m quite familiar with ASP.NET Core and the support for dependency injection out of the box. Controllers can require dependencies by adding a parameter in their constructor. How can dependencies be achieved in WPF UserControls? I tried adding a parameter to the constructor, but that didn’t work. I love the IOC concept and would prefer to bring this forward to WPF. 回答1: I have recently come across this requirement to my project and I solved it this way. For Dependency Injection in .NET Core 3

Dependency Injection in .NET Core 3.0 for WPF

怎甘沉沦 提交于 2021-02-20 05:45:10
问题 I’m quite familiar with ASP.NET Core and the support for dependency injection out of the box. Controllers can require dependencies by adding a parameter in their constructor. How can dependencies be achieved in WPF UserControls? I tried adding a parameter to the constructor, but that didn’t work. I love the IOC concept and would prefer to bring this forward to WPF. 回答1: I have recently come across this requirement to my project and I solved it this way. For Dependency Injection in .NET Core 3

How to lower memory usage in FileStreamResult api

China☆狼群 提交于 2021-02-19 08:37:11
问题 Right now I have an api that gets many results (800k) and it should parse and stream them as CSV. The (kind of) working code I have is this var query = context.address.AsNoTracking(); MemoryStream memoryStream = new MemoryStream(); StreamWriter writer = new StreamWriter(memoryStream); foreach (var row in query) { writer.WriteLine(row.Name+","+row.Surname+","+row.BirthDate); } writer.Flush(); memoryStream.Seek(0, SeekOrigin.Begin); return new FileStreamResult(memoryStream, "application/octet

Prevent ASP.NET Core discovering Controller in separate assembly

旧时模样 提交于 2021-02-19 08:15:30
问题 I've got an ASP.NET Core API that references a nuget package that contains a Controller . By default, this controller is registered and can respond to requests. However, I only want to add this in certain circumstances - e.g. if it's in the DEV environment. My Startup looks like this: services.AddControllers() .AddMvcOptions(cfg => { cfg.Filters.Add(new CustomExceptionFilterAttribute()) }); I expected I'd need to call AddApplicationPart(typeof(ClassInPackage).Assembly) after calling

ef core 2.0 scaffold-dbcontext custom namespace

馋奶兔 提交于 2021-02-19 06:46:06
问题 I am using the ef core 2.0 CLI command scaffold-dbcontext to reverse engineer poco classes from an existing DB (database first). I want to put the generated classes from scaffold-dbcontext in a "Model" folder within my project but I want the namespace of the classes to be something different than "MyProjectName.Model". For example, I want the scaffold-dbcontext generated files to live in the Model folder but I want the namespace of the genereated files to be "MyProjectName.Entities". Is there

How do we secure Swagger UI with Windows Authentication

让人想犯罪 __ 提交于 2021-02-19 06:11:12
问题 We have a .Net Core 2.2 Web Api that uses swagger ui to expose the Web Api definitions. We want to secure this endpoint to only users inside of a certain AD Group. We currently are using Both Windows and Anonymous Authentication. Problem is we cannot enforce Swagger to use Windows Authentication to block users. Any Ideas? 回答1: Although frustrating, the easiest path to securing the Swagger endpoint (via Swashbuckle) I've found thus far is just to put it under its own route and then use a