简体   繁体   English

Azure 管道上的 C# 编译器 (csc.exe)

[英]C# compiler (csc.exe) on Azure Pipelines

I've created a tool that needs you to have csc.exe compiler installed and added to PATH.我创建了一个工具,需要您安装 csc.exe 编译器并将其添加到 PATH。

I want to test that the program works correctly using Azure Pipelines, but I don't know how to install and add it to PATH variable.我想使用 Azure 管道测试程序是否正常工作,但我不知道如何安装并将其添加到 PATH 变量中。

How can I do that (and remove the error 'csc' is not recognized as an internal or external command, operable program or batch file. )?我该怎么做(并删除错误'csc' is not recognized as an internal or external command, operable program or batch file. )?

Here is my pipeline run:这是我的管道运行:

https://dev.azure.com/LumitoLuma/GitHub/_build/results?buildId=30&view=logs&j=12f1170f-54f2-53f3-20dd-22fc7dff55f9 https://dev.azure.com/LumitoLuma/GitHub/_build/results?buildId=30&view=logs&j=12f1170f-54f2-53f3-259dd-22fc7

And here it's code:这是代码:

trigger:
- master

pool:
  vmImage: 'windows-latest'

steps:

- task: PowerShell@2
  inputs:
    targetType: 'inline'
    script: |
      echo "##vso[task.setvariable variable=JAVA_HOME]$(JAVA_HOME_11_X64)"
      echo "##vso[task.setvariable variable=PATH]$(JAVA_HOME_11_X64)\bin;$(PATH)"
  displayName: Setting up Java

- task: NuGetCommand@2
  inputs:
    command: 'custom'
    arguments: 'install Microsoft.Net.Compilers'

- script: install.bat
  displayName: Installing JCC

Thanks a lot for your help!非常感谢你的帮助!

How can I do that (and remove the error 'csc' is not recognized as an internal or external command, operable program or batch file.)?我该怎么做(并删除错误“csc”不被识别为内部或外部命令、可运行程序或批处理文件。)?

The windows-hosted agent has corresponding VS installed. Windows 托管的代理已安装相应的 VS。 Since you're using windows-latest element, Azure DevOps will use the windows2019 with VS2019 installed for your pipeline.由于您使用的是windows-latest元素,因此 Azure DevOps 将使用为您的管道安装了 VS2019 的 windows2019。 You can check the different paths for Csc.exe below:您可以在下面检查Csc.exe的不同路径:

For VS2017 Enterprise :对于VS2017 Enterprise

C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Roslyn\csc.exe

For VS2019 Enterprise :对于VS2019 Enterprise

C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\Roslyn\csc.exe

For .net 4.0 framework :对于.net 4.0 framework

C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe

Workaround:解决方法:

Use multi-line script to Set the path of csc.exe first, then call the install.bat .使用多行脚本先设置csc.exe的路径,然后调用install.bat

- script: |
    SET PATH=%PATH%;"C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\Roslyn\"
    install.bat
  displayName: 'Run a multi-line script'

You can use script above when you're using windows-latest agent.当您使用windows-latest代理时,您可以使用上面的脚本。 And you can modify the path whenever you want to use another agent.并且您可以在想要使用其他代理时修改路径。 Also, distinguish the difference between one-line script and multi-line script:另外,区分单行脚本和多行脚本:

- script: echo Hello, world!
  displayName: 'Run a one-line script'

- script: |
    echo Add other tasks to build, test, and deploy your project.
    echo See https://aka.ms/yaml
  displayName: 'Run a multi-line script'

Let me know if it fixes your issue.让我知道它是否解决了您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM