我正在使用 C# 10 新功能File-scoped namespace declaration。
我有这样的旧代码
namespace SampleCode
{
public class MyClass
{
}
}
Run Code Online (Sandbox Code Playgroud)
我正在将此代码移至
namespace SampleCode;
public class MyClass
{
}
Run Code Online (Sandbox Code Playgroud)
但我有很多警告:IDE0160: Convert to block scoped namespace
我如何确保人们只会收到旧语法的警告?
我有一个像这样的过滤器:
public class CustomFilterAttribute : ActionFilterAttribute, IAuthorizationFilter
{
public MyPropery Property { get; set; }
....
}
Run Code Online (Sandbox Code Playgroud)
我需要为项目中的每个动作运行它
我试图在GlobalFilters中注册它,但我的属性没有被注入
我试过这个解决方案来注册我的过滤器,但它没有被调用
有关如何做到这一点的任何想法?
我正在使用VS2017 RC,我的应用程序以net framework 4.6.1为目标.
我有两个引用System.ValueTuple 4.3的程序集
MyProject.Services MyProject.WebApi
在MyProject.Services中,我有一个类,有这样的方法
public async Task<(int fCount, int cCount, int aCount)> GetAllStatsAsync()
{
// Some code...
return (fCount, cCount, aCount);
}
Run Code Online (Sandbox Code Playgroud)
在MyProject.WebApi中,我有一个使用此方法的控制器:
public async Task<HttpResponseMessage> GetInfoAsync()
{
// Some code...
var stats = await _myClass.GetAllStatsAsync();
var vm = new ViewModel
{
FCount = stats.fCount,
CCount = stats.cCount,
ACount = stats.aCount
};
return Request.CreateResponse(HttpStatusCode.OK, vm);
}
Run Code Online (Sandbox Code Playgroud)
Intellisense正在工作并解构元组,但是当我编译它时失败而没有错误列表窗口中的任何错误.在输出窗口中我有这个错误:
2> MyController.cs(83,31,83,40):错误CS1061:'ValueTuple'不包含'fCount'的定义,并且没有扩展方法'fCount'接受类型'ValueTuple'的第一个参数可以找到(你错过了using指令或程序集引用吗?)2> MyController.cs(84,39,84,49):错误CS1061:'ValueTuple'不包含'cCount'的定义,也没有扩展方法'cCount'接受可以找到类型为'ValueTuple'的第一个参数(你是否缺少using指令或汇编引用?)2> MyController.cs(85,35,85,40):错误CS1061:'ValueTuple'不包含定义对于'aCount'并且没有扩展方法'aCount'可以找到接受类型'ValueTuple'的第一个参数(你是否缺少using指令或汇编引用?)
我尝试添加DEMO和DEMO_EXPERIMENTAL构建标志但仍然失败.
什么是错的?
编辑1:
此代码有效,统计数据解析得很好.我可能遇到了一个bug.
public async Task<HttpResponseMessage> GetInfoAsync()
{
// …Run Code Online (Sandbox Code Playgroud) 我有一个问题,NLog使用此配置记录其内部日志
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
throwExceptions="true"
internalLogFile="${basedir}/App_Data/NLog.log"
internalLogLevel="Trace">
<targets>
<target name="debug"
xsi:type="File"
fileName="${basedir}/App_Data/Site.log" />
</targets>
<rules>
<logger name="*"
writeTo="debug" />
</rules>
</nlog>
Run Code Online (Sandbox Code Playgroud)
目标"debug"运行良好,但是如果我将它设置为例如"D:/NLog.log",则internalLogFile才有效.
知道为什么会这样吗?
这是我的设置:
public class ApplicationUser : IdentityUser<Guid>
{
}
public class ApplicationRole : IdentityRole<Guid>
{
}
public class ApplicationUserLogin : IdentityUserLogin<Guid>
{
}
public class ApplicationUserClaim : IdentityUserClaim<Guid>
{
}
public class ApplicationRoleClaim : IdentityRoleClaim<Guid>
{
}
Run Code Online (Sandbox Code Playgroud)
这是我的UserStore的定义
public class ApplicationUserStore : UserStore<ApplicationUser, ApplicationRole, MyContext, Guid>
{
public ApplicationUserStore(MyContext context, IdentityErrorDescriber describer = null)
: base(context, describer)
{
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的UserManager的定义
public class ApplicationUserManager : UserManager<ApplicationUser>
{
public ApplicationUserManager(IUserStore<ApplicationUser> store, IOptions<IdentityOptions> optionsAccessor,
IPasswordHasher<ApplicationUser> passwordHasher, IEnumerable<IUserValidator<ApplicationUser>> userValidators,
IEnumerable<IPasswordValidator<ApplicationUser>> passwordValidators, ILookupNormalizer keyNormalizer,
IdentityErrorDescriber …Run Code Online (Sandbox Code Playgroud) 我有一个Windows Azure云服务项目的解决方案,可以从VS和命令行编译好.
如果我尝试创建一个包,它可以在VS中正常工作,但是从命令行失败.
这是我的Powershell命令行:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe .\project.sln --%
/p:Configuration="QA" /p:TargetProfile="CloudQA" /p:Platform="Any CPU" /target:Publish
/nr:false
Run Code Online (Sandbox Code Playgroud)
我有这个错误:
"C:\CI\project\project.sln" (Publish target) (1) ->
"C:\CI\project\WindowsAzure\WindowsAzure.ccproj.metaproj" (Publish target) (11) ->
"C:\CI\project\WindowsAzure\WindowsAzure.ccproj" (Publish target) (12) ->
(PrepareRoleItems target) ->
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\Windows Azure Tools\2.0\Microsoft.WindowsAzure.targets(13
02,5): error MSB4096: The item "C:\CI\project\project.WebAPI\project.WebAPI.csproj" in item list "Projec
tReferenceWithConfiguration" does not define a value for metadata "Name". In order to use this metadata, either qualif
y it by specifying %(ProjectReferenceWithConfiguration.Name), or ensure that all items in this list define a value …Run Code Online (Sandbox Code Playgroud) 我在我的机器上安装了NuGet,但我无法禁用黄色警报消息"这是一个开发环境.不会保留任何数据."
我在web.config中更改了这个键
<add key="Gallery.Environment" value="Development" />
Run Code Online (Sandbox Code Playgroud)
至
<add key="Gallery.Environment" value="Production" />
Run Code Online (Sandbox Code Playgroud)
但它仍然出现......任何想法在哪里看?
我正在ASP.Net MVC 4中开始一个新项目,我想知道是否可以使用Autofac MVC3与MVC 4项目集成?
我有一个生成两个报告和许多html文件的脚本,我想用默认浏览器只打开两个html文件.
我的Powershell脚本完成如下:
Invoke-Item C:\Reports\XUReport.htm
Invoke-Item C:\Reports\index.htm
Run Code Online (Sandbox Code Playgroud)
我的脚本只打开第一个文件.最好的方法是什么?
我正在将我的项目设置为使用 dotnet watch 在 Visual Studio 2019 Preview 16.9.0 下的 launchSettings.json 中运行
下面是我的launchSettings.json
{
"profiles": {
"MyWebsite": {
"commandName": "Executable",
"executablePath": "dotnet",
"commandLineArgs": "watch run",
"workingDirectory": "$(ProjectDir)",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"dotnetRunMessages": "true",
"applicationUrl": "https://localhost:5001;http://localhost:5000"
}
}
}
Run Code Online (Sandbox Code Playgroud)
这是我点击时的输出CTRL+F5
watch : Started
The launch profile "(Default)" could not be applied.
A usable launch profile could not be located.
[17:38:49 INF] Starting up
[17:38:49 INF] User profile is available. Using 'C:\Users\MyUser\AppData\Local\ASP.NET\DataProtection-Keys' as key repository and Windows …Run Code Online (Sandbox Code Playgroud) c# ×4
autofac ×2
.net-5 ×1
.net-core ×1
asp.net-core ×1
asp.net-mvc ×1
azure ×1
c#-10.0 ×1
c#-7.0 ×1
editorconfig ×1
msbuild ×1
nlog ×1
nugetgallery ×1