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="Config\System\DataBase.json" CopyToOutputDirectory="Always" />

    <!--因为和csproj同级的config文件是默认打包的,所以这里配置是Update-->
    <Content Update="nlog.config">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    
  </ItemGroup>
  
</Project>

猜你喜欢

转载自www.cnblogs.com/RainFate/p/12747496.html