小编Vic*_*aci的帖子

可以在.NET Framework和.NET Core之间共享的类库

我有一个用.NET 4.0编写的大类库,但是当我在使用.NET Core的Store App中引用它时,它会显示错误.此外,微软刚刚为下一版.NET发布了.NET Core.

我想知道.NET 4.6和.NET Core能够共享哪种类型的项目?类库是否能够做到这一点?

似乎专门为Store Apps发布的.NET Core会让我感到困惑.

.net asp.net .net-core asp.net-core

5
推荐指数
1
解决办法
2230
查看次数

用于vNext中的静态HTML的CORS

我有一个在Visual Studio 2015 RC中运行的MVC6站点

我有一些我希望提供给其他网站的静态HTML文件.我想添加CORS支持(无需添加控制器并以这种方式添加CORS).

有人知道怎么做吗?

cors asp.net-core-mvc asp.net-core

5
推荐指数
1
解决办法
1114
查看次数

记录的扩展方法.一个好主意?

在您看来,以下扩展方法的优缺点是什么?

static class Log
{
    public static string AddToLog(this string input)
    {
        Console.WriteLine(input);
        return input;
    }

    public static string AddToLog(this string input, string format)
    {
        Console.WriteLine(format, input);
        return input;
    }
}
Run Code Online (Sandbox Code Playgroud)

使用场景:

class Program
{
    static void Main(string[] args)
    {
        string tableName = "Bills".AddToLog("Default table name is {0}");

        "Starting...".AddToLog();
        "Creating table".AddToLog();
    }
}
Run Code Online (Sandbox Code Playgroud)

c# string logging extension-methods

3
推荐指数
1
解决办法
1215
查看次数

抽象方法中的C#可选参数

鉴于:

interface IFoo
{
    void Print(string text = "abc");
}

class Bar : IFoo
{
    public void Print(string text = "def")
    {
        Console.WriteLine(text);
    }
}

class Program
{
    static void Main(string[] args)
    {
        Bar b = new Bar();
        b.Print();

        IFoo f = b as IFoo;
        f.Print();
    }
}
Run Code Online (Sandbox Code Playgroud)

输出是:

def
abc
Run Code Online (Sandbox Code Playgroud)

只是我还是这有点奇怪?最初我在两种情况下都期待"def".但是,如果是这种情况,则可选参数抽象方法将毫无用处.但似乎仍然是一个讨厌的错误的良好起点.

c# interface optional-parameters

3
推荐指数
1
解决办法
1762
查看次数

在字符串参数中键入安全性

我的具体问题是关于ASP.NET MVC,但我确信答案可以在ASP.NET之外应用.

你如何处理接受字符串参数但仍然想要类型安全的函数?

在ASP.NET中,扩展方法Html.ActionLink有两个类型为string的参数:string linkText, string actionName.第一个参数是可以从资源加载的文本,但第二个参数是代码中存在的方法的名称.

一种选择是创建一个具有常量字符串的类,而不是写入

 Html.ActionLink("Blah blah", "MyAction");
Run Code Online (Sandbox Code Playgroud)

一个人可以写:

Html.ActionLine("Blah blah", StrongType.MyAction);
Run Code Online (Sandbox Code Playgroud)

MyAction名为的类中的const字符串在哪里StrongType.但是,当可以作为参数传递的方法和其他对象的数量增加时,这将变得很难管理.

第二种选择是使用Reflection以某种方式加载函数的名称,但这似乎太昂贵了.

有没有更好的方法呢?你如何确保你没有像之前提到的字符串参数中的拼写错误?

c# strong-typing

3
推荐指数
1
解决办法
269
查看次数

你如何重新运行dnx.任何文件更改的kestrel命令?

每当更改任何文件时,如何执行我的kestrel服务器以重新启动?而不只是停止?

我试过了

dnx --watch . kestrel
Run Code Online (Sandbox Code Playgroud)

但服务器只是停止,我必须手动重新运行该命令

我也尝试过使用npm watch命令,但这似乎只是绊倒了

watch 'dnx --watch . kestrel' .
Run Code Online (Sandbox Code Playgroud)

dnx asp.net-core

3
推荐指数
1
解决办法
1377
查看次数

PowerShell Copy-Item我做错了什么?

给定dir结构:

x\Code
x\Script\Backup.ps1
Run Code Online (Sandbox Code Playgroud)

Backup.ps1包含:

$BackupDirectoy       = "..\Backup"
$CodeDirectory        = "..\Code"

function BackupCurrentVersion()
{
  New-Item $BackupDirectoy -type directory -force
  Copy-Item $CodeDirectory -destination $BackupDirectory -recurse
}

BackupCurrentVersion
Run Code Online (Sandbox Code Playgroud)

我做错了,因为代码被复制到x\Script\Code而不是x\Backup\Code

问题是什么?

powershell copy-item

2
推荐指数
1
解决办法
3814
查看次数

asp.net核心应用程序构建错误 - 拒绝访问路径Apex_POC.exe.config

我正在尝试使用.Net framework 4.6.1构建我的ASP.NET核心1.0应用程序

但我一直在低于错误 -

错误无法使以下项目可运行:Apex_POC(.NETFramework,Version = v4.6.1)原因:访问路径'C:\ perforce\CFA\Apex\POC\Apex_POC\src\Apex_POC\bin\Debug \net461\win7-x64\Apex_POC.exe.config'被拒绝.Apex_POC C:\ Program Files(x86)\ MSBuild\Microsoft\VisualStudio\v14.0\DotNet\Microsoft.DotNet.Common.Targets 262

我验证了路径是否正确,并确保没有任何文件夹/文件处于只读模式.

另外,验证我可以写入此文件.文件的当前内容如下(默认情况下,一切都没有从我这边添加) -

<configuration>
<runtime>
<gcServer enabled="true"/>
</runtime>
</configuration>
Run Code Online (Sandbox Code Playgroud)

如何解决这个问题?

我的环境是VS2015 Professional update3和Windows 7机器.

感谢和问候

维沙尔

c# visual-studio-2015 asp.net-core asp.net-core-1.0

0
推荐指数
1
解决办法
1139
查看次数