浏览,搜索和希望但找不到直接答案.
无论如何在C#6.0中使用nameofwithouth指定方法名称来获取当前方法名称?
我将测试结果添加到这样的字典中:
Results.Add(nameof(Process_AddingTwoConsents_ThreeExpectedRowsAreWrittenToStream), result);
Run Code Online (Sandbox Code Playgroud)
我希望如果我不必明确指定方法名称,那么我可以复制+粘贴该行,这是一个非工作的例子:
Results.Add(nameof(this.GetExecutingMethod()), result);
Run Code Online (Sandbox Code Playgroud)
如果可能的话我不想使用Reflection.
UPDATE
这不是(如建议的)这个问题的副本.我问是否明确可以使用nameofwithout(!)反射来获取当前方法名称.
出于某种原因,在安装了最新的.NET Core SDK/CLI之后,我无法创建新的Web项目.在"新建ASP.NET Web应用程序"对话框窗口中,我选中了一个"空"项目,并在单击"确定"按钮之前选中了"Web API"复选框.没有显示错误消息,绝对没有任何反应.我尝试了一组项目和复选框+ tabbing和使用空间来调用按钮.它都不起作用.还尝试修复VS并重新启动计算机.
有任何想法吗?
UPDATE
我试图卸载并重新安装Visual Studio,也尝试禁用所有扩展并删除ReSharper.仍然没有成功.我在这里读到有同样问题的人不得不使用NetBeans(恐怖),但通过重新安装VS来解决它,这在我的情况下似乎没有帮助.
更新2
使用Process Monitor,我可以从VS2015中获得的唯一内容是查找ASP.NET模板的成功消息.
更新3
以下Jims建议:
devenv /resetsettings
devenv /resetuserdata
devenv /installvstemplates
Run Code Online (Sandbox Code Playgroud)
现在这会导致错误消息:
我使用crontab.guru创建了一个非常简单的CRON表达式,其中包含在3:15(AM)每天执行的所需行为,结果如下:15 3 * * *
对我来说不幸的是,在Azure门户中这不起作用,但如果我这样添加一个导致0我的表达式0 15 3 * * *,Azure将接受它,同时crontab.guru会告诉我它是错误的.根据规格crontab.guru是:工作日的分钟日期月份.
问题......
以下是我的开发环境的生成发布配置文件:
<?xml version="1.0" encoding="utf-8"?>
<!--
This file is used by the publish/package process of your Web project. You can customize the behavior of this process
by editing this MSBuild file. In order to learn more about this please visit http://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<WebPublishMethod>FileSystem</WebPublishMethod>
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<SiteUrlToLaunchAfterPublish />
<LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
<ExcludeApp_Data>False</ExcludeApp_Data>
<publishUrl>\\dev\webroot</publishUrl>
<DeleteExistingFiles>False</DeleteExistingFiles>
</PropertyGroup>
</Project>
Run Code Online (Sandbox Code Playgroud)
我想要做的是我想象的非常简单,我只想在我想要发布同一个项目的地方添加一个额外的发布网址.不幸的是,我还没能找到任何关于如何以直截了当的方式做到这一点.所有这些都表明我需要实现一些复杂的msdeploy解决方案,或者简单地回退到脚本(即ps/batch + robocopy/xcopy),这是不可取的.
我想象一个人可以简单地做一些事情:
<publishUrl>\\dev\webroot;\\dev2\webroot2</publishUrl>
Run Code Online (Sandbox Code Playgroud)
要么
<itemGroup>
<publishUrl>\\dev\webroot;</publishUrl>
<publishUrl>\\dev2\webroot;</publishUrl>
</itemGroup>
Run Code Online (Sandbox Code Playgroud)
主要问题是: 如何通过FTP或文件系统扩展我的发布配置文件以部署到多个位置?
如果是RTFM响应 - 请参考我可以阅读的内容.
更新 如果可以使用FTP进行多次部署,我也会对这样的解决方案感兴趣.
在你想到它之前,这是不一样的.
我认为这应该是非常自我解释的.我想在Swagger文档中包含类描述.我的Swagger配置如下所示:
config.EnableSwagger(c =>
{
c.SingleApiVersion("v1", "My Api Name");
c.OperationFilter<AddAuthorizationHeaderParameterOperationFilter>();
c.IncludeXmlComments(GetXmlCommentsPath());
}).EnableSwaggerUi(c => { });
Run Code Online (Sandbox Code Playgroud)
而且MyAwesomeController看起来是这样的:
/// <summary>
/// Controller description (is included by Swashbuckle)
/// </summary>
public class MyAwesomeController : ApiController
{
/// <summary>
/// Method description (is included by Swashbuckle)
/// </summary>
public IHttpActionResult Get()
{
return Ok("hello... from the other side");
}
public IHttpActionResult Post([FromBody]MyAwesomeModel model)
{
return Ok("hello... from the other side");
}
}
Run Code Online (Sandbox Code Playgroud)
我MyAwesomeModel看起来像这样:
/// <summary>
/// …Run Code Online (Sandbox Code Playgroud) 我试图在角度应用程序中使用JS将内容复制到剪贴板.
不幸的是,document.queryCommandEnabled("copy")会一直回归false.有没有办法理解为什么浏览器拒绝执行命令?启用命令的标准是什么?
码:
function copyText(text) {
var input = document.createElement('textarea');
document.body.appendChild(input);
input.value = text;
input.focus();
input.select();
var success = document.execCommand('Copy');
input.remove();
return success;
}
Run Code Online (Sandbox Code Playgroud)
我在运行此函数之前测试命令是否已启用:
if(document.queryCommandEnabled("copy")) // Always return false
executeCopy(text_value);
Run Code Online (Sandbox Code Playgroud) IDataProtectionProvider在 Web API 中使用时,IoC 容器使用AddDataProtection( services.AddDataProtection();) 进行配置,并允许使用 DI 来检索IDataProtectionProvider服务中的 a:
private readonly IDataProtectionProvider _dataProtectionProvider;
public CipherService(IDataProtectionProvider dataProtectionProvider)
{
_dataProtectionProvider = dataProtectionProvider;
}
Run Code Online (Sandbox Code Playgroud)
如果我想测试我的CipherService(在我的情况下使用 Xunit),如果不使用 DI,我将无法完成这项工作,所以我的问题是;
问:如何IDataProtectionProvider在测试项目中使用 DI 或其他方式制作?
我在Docker(在Kubernetes中)运行.NET Core应用程序,将环境变量传递给Docker容器并在我的应用程序中使用它们.
在我的.NET Core应用程序中,我有以下C#类:
public class EnvironmentConfiguration
{
public string EXAMPLE_SETTING { get; set; }
public string MY_SETTING_2 { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我设置了appsettings这样的:
config.
AddJsonFile("appsettings.json").
AddJsonFile($"appsettings.docker.json", true).
AddEnvironmentVariables();
Run Code Online (Sandbox Code Playgroud)
DI设置:
services.Configure<EnvironmentConfiguration>(Configuration);
Run Code Online (Sandbox Code Playgroud)
在我的控制器中,我使用它:
[ApiVersion("1.0")]
[Route("api/v{version:apiVersion}/my")]
public class MyController : Controller
{
private readonly IOptions<EnvironmentConfiguration> _environmentConfiguration;
public MyController(IOptions<EnvironmentConfiguration> environmentConfiguration)
{
_environmentConfiguration = environmentConfiguration;
}
}
Run Code Online (Sandbox Code Playgroud)
我跑码头:
docker run -p 4000:5000 --env-file=myvariables
Run Code Online (Sandbox Code Playgroud)
该文件myvariables如下所示:
EXAMPLE_SETTING=example!!!
MY_SETTING_2=my-setting-2!!!!
Run Code Online (Sandbox Code Playgroud)
这有效.我可以使用我的_environmentConfiguration并看到我的变量已设置.
但是...我想将环境变量与appsettings合并,以便在找不到环境变量时将appsettings的值用作回退.以某种方式合并这两行:
services.Configure<EnvironmentConfiguration>(settings => Configuration.GetSection("EnvironmentConfiguration").Bind(settings));
services.Configure<EnvironmentConfiguration>(Configuration);
Run Code Online (Sandbox Code Playgroud)
这有点可能吗?
我的后备计划是继承EnvironmentConfiguration该类并使用单独的DI来注入两个单独的配置,然后在代码中"手动"合并它们,但这种解决方案是不可取的.
我刚刚使用文件系统发布到本地IIS应用程序发布了一个AngularJS/WebAPI项目,我可以在浏览器中打开该网站.不幸的是,不能加载诸如图像,css等资源.当我尝试访问位于子文件夹中的任何文件时,我仍然从服务器收到HTTP 200,但正文是空的.我记得几年前我有过这个问题,但我不记得为什么会这样.
请求
GET http://localhost/Content/images/common/logotype.png HTTP/1.1
Host: XX.XXX.XX.XXX
Connection: keep-alive
Cache-Control: max-age=0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.130 Safari/537.36
Accept-Encoding: gzip, deflate, sdch
Accept-Language: en-US,en;q=0.8,sv;q=0.6
Run Code Online (Sandbox Code Playgroud)
响应
HTTP/1.1 200 OK
Server: Microsoft-IIS/8.5
X-Powered-By: ASP.NET
Date: Tue, 25 Aug 2015 07:56:12 GMT
Content-Length: 0
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,根本没有正文,但文件夹中存在图像,我可以从文件系统中打开它.我猜想如果这是一个特权问题,服务器会返回403或类似的错误,而不是200 OK?
我有一个带有OAuth身份验证的MVC项目,每次我尝试调试项目时,在配置IAppBuilder时都会遇到FileLoadException.我已经使用PMC安装了Microsoft.Owin.Security.Oauth 3.0.1版,但我想某处仍然是对旧版本软件包的引用,因为......
这是例外:
这是抛出的地方:
public partial class Startup
{
public void Configuration(IAppBuilder app)
{
ConfigureAuth(app); //Exception is thrown here
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的packages.config:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Antlr" version="3.4.1.9004" targetFramework="net45" />
<package id="CommonServiceLocator" version="1.3" targetFramework="net45" />
<package id="EntityFramework" version="6.0.0" targetFramework="net45" />
<package id="jQuery" version="1.10.2" targetFramework="net45" />
<package id="jQuery.Validation" version="1.11.1" targetFramework="net45" />
<package id="log4net" version="2.0.3" targetFramework="net45" />
<package id="Microsoft.AspNet.Identity.Core" version="1.0.0" targetFramework="net45" />
<package id="Microsoft.AspNet.Identity.EntityFramework" version="1.0.0" targetFramework="net45" />
<package id="Microsoft.AspNet.Identity.Owin" version="1.0.0" targetFramework="net45" />
<package id="Microsoft.AspNet.Mvc" version="5.0.0" targetFramework="net45" />
<package id="Microsoft.AspNet.Razor" version="3.2.3" targetFramework="net45" …Run Code Online (Sandbox Code Playgroud) c# ×5
.net-core ×2
owin ×2
.net ×1
angularjs ×1
asp.net ×1
asp.net-core ×1
asp.net-mvc ×1
azure ×1
c#-6.0 ×1
clipboard ×1
config ×1
cron ×1
deployment ×1
docker ×1
encryption ×1
http ×1
iis ×1
javascript ×1
msbuild ×1
nameof ×1
reflection ×1
swagger ×1
swashbuckle ×1