当前位置: 代码网 > it编程>编程语言>Asp.net > C#系列-手把手教你安装 Visual Studio配置C#开发环境,创建第一个C#程序

C#系列-手把手教你安装 Visual Studio配置C#开发环境,创建第一个C#程序

2024年08月02日 Asp.net 我要评论
在命令行工具中输入csc hello.cs,回车(此步骤需要电脑有csc 命令环境)命令行工具输入hello 或 hello.exe 或双击运行 hello.exe。若提示无法识别 csc 命令,需C#命令行编译环境变量(Window10)打开 CMD 命令行工具,cd 进入 hello.cs 文件所在目录。小伙伴们,( ̄ω ̄( ̄ω ̄〃 ( ̄ω ̄〃)ゝ我们明天再见啦~~我们就可以看到屏幕输出“Hello World!当前目录自动生成 hello.exe可执行文件。欢迎大家指出文章需要改正之处~

安装 visual studio配置c#开发环境

下载软件

点击此处开始下载

安装依赖

选择.net desktop development

在这里插入图片描述

安装完成,重启电脑

手把手教你解决异常couldnt install microsoft.visualcpp.redist.14

something went wrong with the install.

you can troubleshoot the package failures by:

    1. search for solutions using the search url below for each package failure
    2. modify your selections for the affected workloads or components and then retry the installation
    3. remove the product from your machine and then install again

if the issue has already been reported on the developer community, you can find solutions or workarounds there. if the issue has not been reported, we encourage you to create a new issue so that other developers will be able to find solutions or workarounds. you can create a new issue from within the visual studio installer in the upper-right hand corner using the "provide feedback" button.

================================================================================

package 'microsoft.visualcpp.redist.14,version=14.38.33130,chip=x86' failed to install.
    search url
        https://aka.ms/vssetuperrorreports?q=packageid=microsoft.visualcpp.redist.14;packageaction=install;returncode=-2147023274
    details
        command executed: "c:\windows\syswow64\\windowspowershell\v1.0\powershell.exe" -nologo -noprofile -noninteractive -executionpolicy unrestricted -inputformat none -command "& """c:\programdata\microsoft\visualstudio\packages\microsoft.visualcpp.redist.14,version=14.38.33130,chip=x86\vcredistinstall.ps1""" -payloaddirectory """c:\programdata\microsoft\visualstudio\packages\microsoft.visualcpp.redist.14,version=14.38.33130,chip=x86""" -architecture x86 -logfile """c:\users\xx\appdata\local\temp\dd_setup_20240119115035_255_microsoft.visualcpp.redist.14.log"""; exit $lastexitcode"
        return code: -2147023274
        return code details: error opening installation log file. verify that the specified log file location exists and that you can write to it.
    log

解决方案1
  • 找到这个目录c:\programdata\microsoft\visualstudio\packages
  • 直接搜索vc_redist关键词
  • 找到这个vc_redist.x64.exe文件,一般会有两个,直接全部双击安装
  • 返回vs installer 界面点击:更多—修复


解决方案2
  • 当遇到报错,点击错误信息下面的查看日志选项,打开日志文件(就像上面粘贴的那些异常信息)
  • 在错误日志中寻找安装文件的路径,类似于:c:\programdata\microsoft\visualstudio\packages\microsoft. visualcp . redist .14. latest,version=xx.xx.xxxxx
  • 打开此路径位置
  • 看到一个vc redist.xxx.exe
  • 安装运行它
  • 关机重启
  • 重新运行vs installer 界面点击:更多—修复

创建第一个c#程序

创建项目
  • 启动 visual studio;
  • 在菜单栏上依次选择“文件”->“新建”->“项目”;
  • 从模板中选择“blank solution”,然后点击“下一步”;
  • 指定项目名称等信息,然后单击“创建”按钮;
  • 在右侧项目空白处,右键新建文件,名字为‘hello.cs’






编写代码
using system;

namespace c.biancheng.net
{
    class program
    {
        static void main(string[] args)
        {
            /*第一个c#程序*/
            console.writeline("hello world!");
            console.readkey();
        }
    }
}
配置环境

若提示无法识别 csc 命令,需c#命令行编译环境变量(window10)

  • 打开计算机,右键单击
  • 属性-高级系统设置-环境变量-系统变量
  • 找到变量 path, 添加路径 (可以打开路径看一下,尽量选择最新版本进行添加)
  • 多个环境变量使用;分隔
c:\windows\http://microsoft.net\framework\v版本号
运行
  • 打开 cmd 命令行工具,cd 进入 hello.cs 文件所在目录

  • 在命令行工具中输入csc hello.cs,回车(此步骤需要电脑有csc 命令环境)

  • 当前目录自动生成 hello.exe可执行文件

  • 命令行工具输入hello 或 hello.exe 或双击运行 hello.exe

  • 我们就可以看到屏幕输出“hello world!”啦~

  • 今天就写到这里啦~

  • 小伙伴们,( ̄ω ̄( ̄ω ̄〃 ( ̄ω ̄〃)ゝ我们明天再见啦~~

  • 大家要天天开心哦

在这里插入图片描述

欢迎路过的小哥哥小姐姐们提出更好的意见哇~~
(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com