我的文本文件在我的类库项目中。我将其构建操作设置为内容并将复制到输出目录设置为复制(如果更新),因此 .csproj 具有如下部分:
<ItemGroup>
<Content Include="MyFile.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
Run Code Online (Sandbox Code Playgroud)
我这样做是因为我需要使用我的类库中的文本文件,并且不能将其作为嵌入式资源,因为我希望允许最终用户对其进行编辑。当我使用 VS 2017 创建包时,它给了我一个 .nuspec ,其中包含如下部分:
<contentFiles>
<files include="any/net46/MyFile.txt" buildAction="Content" />
<files include="any/netstandard1.3/MyFile.txt" buildAction="Content" />
</contentFiles>
Run Code Online (Sandbox Code Playgroud)
然后,当我从另一个项目引用包时,MyFile.txt 出现在项目的根目录中,构建操作设置为内容,但复制到输出目录设置为不复制。我只想将该文件包含在 .dll 旁边,而不是包含在引用项目中。
我必须能够使用RestSharp从Rest API流式传输大型文件.这样做的规范方法是在请求上设置'ResponseWriter'属性:
var client = new RestClient
var request = new RestRequest();
IRestResponse response;
request.ResponseWriter = connectStream => {
if(response.StatusCode == ResponseStatus.OK)
{
CloudStorage.UploadFromStream(connectStream);
}
else
{
LoggerService.LogErrorFromStream(connectStream);
}
};
response = client.Execute(request);
Run Code Online (Sandbox Code Playgroud)
我的问题是,在 RestSharp完成请求我的ResponseWriter处理整个流之前,'response'对象(包括状态,状态代码,标题等)才可用.
这似乎违反直觉,因为用户当然可能希望根据响应状态更改响应流的处理方式.
在开始处理响应主体的流之前,如何获取此状态信息?
我的 .NET Core 控制台应用程序具有以下 .csproj(请注意 NuGet 包参考):
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp1.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Net.Compilers.netcore" Version="1.3.2" />
</ItemGroup>
</Project>
Run Code Online (Sandbox Code Playgroud)
这是我的 .NET Core 控制台应用程序的源代码,我尝试编译的 .NET Core 控制台应用程序包含在“source”变量中:
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using System.Reflection;
public class Program
{
public static void Main()
{
string source =
@"using System;
public static class Program
{
public static void Main()
{
string input = Console.ReadLine();
Console.WriteLine(input);
}
}";
var compilation = CSharpCompilation.Create(
assemblyName: "source",
syntaxTrees: new[] { CSharpSyntaxTree.ParseText(source) },
references: new[] { MetadataReference.CreateFromFile(typeof(object).GetTypeInfo().Assembly.Location) }); …Run Code Online (Sandbox Code Playgroud) 在我的 WPF MVVM 应用程序中,我有一些永远运行的后台任务,我像这样创建它:
Task.Run(async () =>
{
while (true)
{
if (IsStarted)
{
// Do some processing and update the UI via bound properties.
}
await Task.Delay(300);
}
});
Run Code Online (Sandbox Code Playgroud)
我应该把它改成await Task.Delay(300).ConfigureAwait(false);吗?我环顾四周无法判断,但听起来它可能是多余的,因为它已经在线程池线程中等待。