zoukankan      html  css  js  c++  java
  • ASP.NET Core 发布

     命令行发布

     如果没有打包运行时文件,可以添加下参数   --self-contained true  

    # 需要依赖运行时环境
    dotnet publish -c Release  -o F:Release
    
    # 和运行时文件一起发布,不需要依赖运行时环境
    dotnet publish -c Release  -o F:Release  -r win-x64
    
    # 和运行时文件一起打包到一个exe文件中,这一个exe包含了所有的文件
    dotnet publish -c Release  -o F:Release  -r win-x64 /p:PublishSingleFile=true /p:PublishTrimmed=true
    • -c:发布模式,有Debug和 Release 两个值一般都是Release
    • -o:发布文件路径
    • -r:需要部署程序的系统类型,一般的值有三种 win-x64、win-x86、linux-x64
    • /p: PublishSingleFile=true 所有打包到一个exe中;PublishTrimmed=true 压缩这个exe大小

    Visual Studio 发布

    发布下图项目并附带相关配置文件

    可以直接修改文件的属性的值

      

     或者直接修改 WebApplication1.csproj  项目文件 

    <Project Sdk="Microsoft.NET.Sdk.Web">
      <PropertyGroup>
        <Version>1.0.0.4</Version>
        <TargetFramework>netcoreapp3.1</TargetFramework>
        <IsTransformWebConfigDisabled>true</IsTransformWebConfigDisabled>
        <Configurations>Debug;Release;</Configurations>
        <LangVersion>latest</LangVersion>
      </PropertyGroup>
    
      <ItemGroup>
    
        <!--★★★★★打包不能配置文件夹,只能配置文件★★★★★-->
        
        
        <!--打包时去掉某些文件-->
        <Content Remove="appsettings.*.json" />
        <None Include="appsettings.*.json" />
        
        <!--打包Config目录是所有xml文件-->
        <Content Update="Config***.xml">
          <CopyToOutputDirectory>Always</CopyToOutputDirectory>
        </Content>
    
        <!--打包某一个文件-->
        <Content Include="ConfigSystemDataBase.json" CopyToOutputDirectory="Always" />
    
        <!--因为和csproj同级的config文件是默认打包的,所以这里配置是Update-->
        <Content Update="nlog.config">
          <CopyToOutputDirectory>Always</CopyToOutputDirectory>
        </Content>
        
      </ItemGroup>
      
    </Project>
  • 相关阅读:
    开发day7
    开发day6
    开发day5
    开发day4
    开发day3
    开发day2
    开发day1
    假期学习2/8
    什么是栈帧
    JDK、JRE和JVM到底是什么
  • 原文地址:https://www.cnblogs.com/RainFate/p/12747496.html
Copyright © 2011-2022 走看看