首页 技术 正文
技术 2022年11月6日
0 收藏 541 点赞 950 浏览 1125 个字

1、asp.net core控制台程序

static void Main(string[] args)
{
int times=;
while(times>=)
{
Console.WriteLine("Hello World!");
times--;
Thread.Sleep();
}
}

2、发布

发布前,修改test2.csproj文件(项目名称为test2)

<Project Sdk="Microsoft.NET.Sdk">  <PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.</TargetFramework>
<RuntimeIdentifier>centos.-x64</RuntimeIdentifier>
</PropertyGroup></Project>

主要添加 <RuntimeIdentifier>centos.7-x64</RuntimeIdentifier> 这句(如果把centos.7-x64改为win10-x64,则发布为exe程序,运行在windows上。)。

使用命令“dotnet publish”发布在test2\bin\Debug\netcoreapp2.1\centos.7-x64目录下,如下图:

VisualStudioCode创建的asp.net core控制台程序部署到linux

把所有文件上传到linux服务器(我的linux上放代码目录为/var/wwwroot/netconsole)

切到publish下(即/var/wwwroot/netconsole/publish),输入命令“dotnet test2.dll”,如下图:

VisualStudioCode创建的asp.net core控制台程序部署到linux

3、创建服务

新建自定义服务:vim /etc/systemd/system/mydotnetconsole.service,服务代码内容如下:

[Unit]
Description=dotnet console demo running on linux[Service]
WorkingDirectory=/var/wwwroot/netconsole
ExecStart=/usr/bin/dotnet /var/wwwroot/netconsole/test2.dll
Restart=always
RestartSec=
SyslogIdentifier=dotnet core console
User=root
Environment=ASPNETCORE_ENVIRONMENT=Production [Install]
WantedBy=multi-user.target

启动服务 systemctl start mydotnetconsole.service

查看 systemctl status netconsole -l     如下图:

VisualStudioCode创建的asp.net core控制台程序部署到linux

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,085
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,560
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,409
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,182
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,819
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,902