小编Bai*_*ler的帖子

.Net 5 发布单个文件 - 生成 exe 和 dll

我正在使用 VS 2019 和 .Net 5 来​​构建一个简单的控制台应用程序。我想与朋友分享这个应用程序,所以我尝试将它发布为单个文件,但我不断收到一些额外的 DLL,可执行文件需要正确运行这些 DLL。

编辑:将这个项目切换到 .net core 3.1 可以按预期工作我能够导出单个 Exe 文件而无需任何所需的 DLL。

点网 CLI: dotnet publish -c Release -o publish -p:PublishReadyToRun=true -p:PublishSingleFile=true -p:PublishTrimmed=true --self-contained true

项目:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net5.0</TargetFramework>
    <PublishSingleFile>true</PublishSingleFile>
    <RuntimeIdentifier>win-x64</RuntimeIdentifier>
    <PlatformTarget>x64</PlatformTarget>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="HtmlAgilityPack" Version="1.11.28" />
  </ItemGroup>
</Project>
Run Code Online (Sandbox Code Playgroud)

输出

c# .net-core .net-5

18
推荐指数
1
解决办法
7616
查看次数

.Net Core Web Api 这个随机端口分配来自哪里?

我正在使用 docker-compose 托管使用 .Net Core 模板创建的 .Net Core Web 应用程序。

我的 docker-compose 如下:

version: '3.4'

services:
  db:
    image: mysql:5.7
    container_name: mysql_db
    volumes: 
       - db_data:/var/lib/mysql
    environment:
      MYSQL_ROOT_PASSWORD: "root"
      MYSQL_HOST: "localhost"
      MYSQL_ROOT_HOST: "%"

  todoservice:
    image: ${DOCKER_REGISTRY}todoservice
    ports: 
      - "8000:80"
    build:
      context: .
      dockerfile: ToDoService/Dockerfile
    depends_on:
      - db

volumes:
  db_data: 
Run Code Online (Sandbox Code Playgroud)

其中我声明我的主机端口 8000 将映射到此 docker 容器上的端口 80。我还有这个 dockerfile 定义了如何构建我的 .Net Core Web Api。

FROM microsoft/aspnetcore:2.0 AS base
WORKDIR /app
EXPOSE 80

FROM microsoft/aspnetcore-build:2.0 AS build
WORKDIR /src
COPY ToDoService/ToDoService.csproj ToDoService/
RUN dotnet restore ToDoService/ToDoService.csproj …
Run Code Online (Sandbox Code Playgroud)

c# docker

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

Angular 4 api 调用转向对 json 的响应返回未定义

我正在关注一个示例,他们正在像这样调用本地 web api。

return this.http.get("http://localhost:26264/api/news").map((response: Response)=>{
  response.json();
});
Run Code Online (Sandbox Code Playgroud)

如果您在.json()通话前查看response 的值,一切看起来都很好。

然后我在做这个,

var data = this.authService.Login(value.Email, value.Password).subscribe((res: any)=>{
    console.log(res);
  });
Run Code Online (Sandbox Code Playgroud)

此时 res 的值未定义?忽略我正在为新闻控制器 api 调用登录方法这一事实。我更改了 api 端点,因为在此之前我遇到了其他错误。

json angular

4
推荐指数
1
解决办法
4807
查看次数

从FileStream进行视频流的.NET Core 2.0 Web API

我发现了很多示例,这些示例使用的对象在我的应用程序中不可用,并且似乎与我的.NET Core Web API版本不匹配。本质上,我正在一个项目上,该项目将<video>在网页上具有标签,并且想要使用来自服务器的流而不是通过路径直接提供文件来加载视频。原因之一是文件的来源可能会更改,并且通过路径提供文件不是我的客户想要的。因此,我需要能够打开流并异步写入视频文件。

由于某种原因,这会产生JSON数据,所以这是错误的。但是我只是不明白将流视频文件发送到<video>HTML标签中需要做什么。

当前代码:

[HttpGet]
public HttpResponseMessage GetVideoContent()
{
    if (Program.TryOpenFile("BigBuckBunny.mp4", FileMode.Open, out FileStream fs))
    {
        using (var file = fs)
        {
            var range = Request.Headers.GetCommaSeparatedValues("Range").FirstOrDefault();
            if (range != null)
            {
                var msg = new HttpResponseMessage(HttpStatusCode.PartialContent);
                var body = GetRange(file, range);
                msg.Content = new StreamContent(body);
                msg.Content.Headers.Add("Content-Type", "video/mp4");
                //msg.Content.Headers.Add("Content-Range", $"0-0/{fs.Length}");
                return msg;
            }
            else
            {
                var msg = new HttpResponseMessage(HttpStatusCode.OK);
                msg.Content = new StreamContent(file);
                msg.Content.Headers.Add("Content-Type", "video/mp4");
                return msg;
            }
        }
    }
    else
    {
        return new …
Run Code Online (Sandbox Code Playgroud)

c# video-streaming html5-video asp.net-core-2.0

4
推荐指数
1
解决办法
7312
查看次数