I've created a tool that needs you to have csc.exe compiler installed and added to 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.
How can I do that (and remove the error '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
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.)?
The windows-hosted agent has corresponding VS installed. Since you're using windows-latest element, Azure DevOps will use the windows2019 with VS2019 installed for your pipeline. You can check the different paths for Csc.exe below:
For VS2017 Enterprise:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Roslyn\csc.exe
For VS2019 Enterprise:
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\Roslyn\csc.exe
For .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.
- 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. 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'
Related
Asking very generally as I am completely new to Gitlabs CI/CD and CI/CD in general.
I have implemented a C# Net Framework application in Visual Studio 2017 and manage it with Gitlab.
Now I want to automatically create a binary of that application with the GitLab CI/CD feature.
I already have a runner ( docker based on Windows) registered in GitLab and run jobs.
My current YAML file looks as following:
default:
image: ruby:2.7.2
job:
stage: build
only:
- branches
script:
- set -m
- echo "Start build"
- '"C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\MSBuild.exe" /p:Configuration=Release /clp:ErrorsOnly; Build "NameOfApplication.sln"'
artifacts:
expire_in : 1 days
paths:
- '.\IndoorNavigation\bin\Release'
How can I now get the artifact / binary MSBuild generates? It should show up in pipelines for download right? I already tried the artifacts option with different path unsuccessfully.
Would also be happy for links to good tutorials as I have not found any tutorial that helped me.
Edit: Output of the Job:
Running with gitlab-runner 14.3.1 (8b63c432)
on docker-runner 2tZDZ6cX
Preparing the "docker" executor
Using Docker executor with image ruby:2.7.2 ...
Pulling docker image ruby:2.7.2 ...
Using docker image sha256:e6c92ed2f03be9788b80944e148783bef8e7d0fa8d9755b62e9f03429e85a327 for ruby:2.7.2 with digest ruby#sha256:1dd0106849233fcd913b7c4608078fa1a53a5e3ce1af2a55e4d726b0d8868e2f ...
Preparing environment
00:01
Running on runner-2tzdz6cx-project-1235-concurrent-0 via d98bb3402720...
Getting source from Git repository
Fetching changes with git depth set to 50...
Reinitialized existing Git repository in /builds/user/NameOfApplication/.git/
Checking out 2e50e922 as master...
Skipping Git submodules setup
Executing "step_script" stage of the job script
Using docker image sha256:e6c92ed2f03be9788b80944e148783bef8e7d0fa8d9755b62e9f03429e85a327 for ruby:2.7.2 with digest ruby#sha256:1dd0106849233fcd913b7c4608078fa1a53a5e3ce1af2a55e4d726b0d8868e2f ...
$ set -m
$ echo "Start build" - '"C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\MSBuild.exe" /p:Configuration=Release /clp:ErrorsOnly; Build "NameOfApplication.sln"'
Start build - "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\MSBuild.exe" /p:Configuration=Release /clp:ErrorsOnly; Build "NameOfApplication.sln"
Uploading artifacts for successful job
00:01
Uploading artifacts...
WARNING: .\NameOfApplication\bin\Release: no matching files
ERROR: No files to upload
Cleaning up project directory and file based variables
00:01
Job succeeded
I have a project using .net core 3.1 with Windows Forms and a Windows Application Packaging project in the same solution. I had this pipeline working for the past couple of months and now it seems to have stopped working.
I'm not sure, but it seems to be failing to find a .target file from within the hosted agent I'm using to run the pipeline.
I tried using the VS Msbuild step and the MSBuild standalone one, also tried specific NuGet versions(5.2.0,5.8.0,5.10.0) with Nuget Restore step. But nothing seems to help.
Does anyone have some clue where to start looking?
The error:
...
CopyFilesToOutputDirectory:
Copying file from "D:\a\1\s\PrinterAgent\PrinterAgent\obj\Release\netcoreapp3.1\PrinterAgent.dll" to "D:\a\1\s\PrinterAgent\PrinterAgent\bin\Release\netcoreapp3.1\PrinterAgent.dll".
PrinterAgent -> D:\a\1\s\PrinterAgent\PrinterAgent\bin\Release\netcoreapp3.1\PrinterAgent.dll
Copying file from "D:\a\1\s\PrinterAgent\PrinterAgent\obj\Release\netcoreapp3.1\PrinterAgent.pdb" to "D:\a\1\s\PrinterAgent\PrinterAgent\bin\Release\netcoreapp3.1\PrinterAgent.pdb".
Done Building Project "D:\a\1\s\PrinterAgent\PrinterAgent\PrinterAgent.csproj" (default targets).
##[error]C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Microsoft\DesktopBridge\Microsoft.DesktopBridge.targets(16,3): Error MSB4019: The imported project "C:\hostedtoolcache\windows\dotnet\sdk\3.1.411\Sdks\Microsoft.NET.Sdk\Sdk\Sdk.NuGet.targets" was not found. Confirm that the expression in the Import declaration "C:\hostedtoolcache\windows\dotnet\sdk\3.1.411\Sdks\Microsoft.NET.Sdk\Sdk\Sdk.NuGet.targets" is correct, and that the file exists on disk.
Project "D:\a\1\s\PrinterAgent\PrinterAgent.sln" (1) is building "D:\a\1\s\PrinterAgent\PrinterAgent.Package\PrinterAgent.Package.wapproj" (3) on node 1 (default targets).
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Microsoft\DesktopBridge\Microsoft.DesktopBridge.targets(16,3): error MSB4019: The imported project "C:\hostedtoolcache\windows\dotnet\sdk\3.1.411\Sdks\Microsoft.NET.Sdk\Sdk\Sdk.NuGet.targets" was not found. Confirm that the expression in the Import declaration "C:\hostedtoolcache\windows\dotnet\sdk\3.1.411\Sdks\Microsoft.NET.Sdk\Sdk\Sdk.NuGet.targets" is correct, and that the file exists on disk. [D:\a\1\s\PrinterAgent\PrinterAgent.Package\PrinterAgent.Package.wapproj]
Done Building Project "D:\a\1\s\PrinterAgent\PrinterAgent.Package\PrinterAgent.Package.wapproj" (default targets) -- FAILED.
Done Building Project "D:\a\1\s\PrinterAgent\PrinterAgent.sln" (default targets) -- FAILED.
Build FAILED.
"D:\a\1\s\PrinterAgent\PrinterAgent.sln" (default target) (1) ->
"D:\a\1\s\PrinterAgent\PrinterAgent.Package\PrinterAgent.Package.wapproj" (default target) (3) ->
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Microsoft\DesktopBridge\Microsoft.DesktopBridge.targets(16,3): error MSB4019: The imported project "C:\hostedtoolcache\windows\dotnet\sdk\3.1.411\Sdks\Microsoft.NET.Sdk\Sdk\Sdk.NuGet.targets" was not found. Confirm that the expression in the Import declaration "C:\hostedtoolcache\windows\dotnet\sdk\3.1.411\Sdks\Microsoft.NET.Sdk\Sdk\Sdk.NuGet.targets" is correct, and that the file exists on disk. [D:\a\1\s\PrinterAgent\PrinterAgent.Package\PrinterAgent.Package.wapproj]
0 Warning(s)
1 Error(s)
Time Elapsed 00:00:07.08
##[error]Process 'msbuild.exe' exited with code '1'.
Pipeline Definition:
Using windows-2019 agent
pool:
name: Azure Pipelines
demands:
- msbuild
- azureps
#Your build pipeline references the ‘packageName’ variable, which you’ve selected to be settable at queue time. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab, and then select the option to make it settable at queue time. See https://go.microsoft.com/fwlink/?linkid=865971
#Your build pipeline references the ‘packageName’ variable, which you’ve selected to be settable at queue time. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab, and then select the option to make it settable at queue time. See https://go.microsoft.com/fwlink/?linkid=865971
#Your build pipeline references the ‘BuildPlatform’ variable, which you’ve selected to be settable at queue time. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab, and then select the option to make it settable at queue time. See https://go.microsoft.com/fwlink/?linkid=865971
#Your build pipeline references the ‘BuildConfiguration’ variable, which you’ve selected to be settable at queue time. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab, and then select the option to make it settable at queue time. See https://go.microsoft.com/fwlink/?linkid=865971
#Your build pipeline references the ‘msixInstallUrl’ variable, which you’ve selected to be settable at queue time. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab, and then select the option to make it settable at queue time. See https://go.microsoft.com/fwlink/?linkid=865971
#Your build pipeline references an undefined variable named ‘signingCert.password’. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab. See https://go.microsoft.com/fwlink/?linkid=865972
#Your build pipeline references an undefined variable named ‘mySecureFile.secureFilePath’. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab. See https://go.microsoft.com/fwlink/?linkid=865972
variables:
packageVersion: '1.0.0'
steps:
- task: UseDotNet#2
displayName: 'Use .NET Core sdk 3.1.411'
inputs:
version: 3.1.411
- powershell: |
[xml]$manifest= get-content ".\PrinterAgent\PrinterAgent.Package\Package.appxmanifest"
$manifest.Package.Identity.Version = "$(packageVersion).$(Build.BuildId)"
$manifest.Package.Identity.Name = "demo-864d9095-955f-4d3c-adb0-6574a5acb88b"
$manifest.Package.Properties.DisplayName = "$(packageName)"
$manifest.Package.Applications.Application.VisualElements.DisplayName = "$(packageName)"
$manifest.save(".\PrinterAgent\PrinterAgent.Package\Package.appxmanifest")
displayName: 'PowerShell Script'
- task: DotNetCoreCLI#2
displayName: 'dotnet restore'
inputs:
command: restore
projects: '**/*.csproj'
- task: DownloadSecureFile#1
displayName: 'Download secure file'
inputs:
secureFile: <fileId>
#Fails here
- task: MSBuild#1
displayName: 'Build solution **/*.sln'
inputs:
msbuildVersion: 16.0
platform: '$(BuildPlatform)'
configuration: '$(BuildConfiguration)'
msbuildArguments: '/p:AppInstallerUri=$(msixInstallUrl) /p:AppxPackageDir="$(Build.ArtifactStagingDirectory)" /p:UapAppxPackageBuildMode=SideLoadOnly /p:GenerateAppInstallerFile=true /p:PackageCertificatePassword="$(signingCert.password)" /p:PackageCertificateKeyFile="$(mySecureFile.secureFilePath)" /p:AppInstallerCheckForUpdateFrequency=OnApplicationRun /p:AppInstallerUpdateFrequency=1 /p:AppInstallerShowPrompt=true'
- task: PublishBuildArtifacts#1
displayName: 'Publish Artifact: drop'
inputs:
PathtoPublish: '$(build.artifactstagingdirectory)'
condition: succeededOrFailed()
- task: AzureCLI#2
displayName: 'Azure CLI CleanUp blob'
inputs:
azureSubscription: <azureSubscription>
scriptType: ps
scriptLocation: inlineScript
inlineScript: 'az storage blob delete-batch --account-name <storage> --source ''$web'''
- task: AzureFileCopy#4
displayName: 'AzureBlob File Copy'
inputs:
SourcePath: '$(build.artifactstagingdirectory)/*'
azureSubscription: <azureSubscription>
Destination: AzureBlob
storage: <storageName>
ContainerName: '$web'
I finally fixed it myself.
You need the latest .NET SDK to get rid of MSB4019:
- task: UseDotNet#2
displayName: 'Use .NET Core sdk 3.1.x'
inputs:
version: 3.1.x
This will introduce another issue (NETSDK1004, see my comments), that can be fixed by restoring the packaging project explicitly, but that requires msbuild, try something like:
- task: MSBuild#1
inputs:
solution: PrinterAgent.Package\PrinterAgent.Package.wapproj
platform: '$(BuildPlatform)'
configuration: '$(BuildConfiguration)'
msbuildArguments: '/t:restore'
You might also try to modify the existing msbuildArguments by adding: /t:restore;build
Hi I've got a solution that has multiple projects held within it where I'm hoping to automate the build and deployment of the webapplication within the project.
on my HD the dir looks like C:\Users\mleip\source\repos\edocs.utils.bluebeam-api\edocs.utils.bluebeam-api.Caller\edocs.utils.CDEComms , however, when I run the below yaml
i get
MSBUILD : error MSB1003: Specify a project or solution file. The current working directory does not contain a project or solution file.
trigger:
- master
pool:
vmImage: 'ubuntu-latest'
variables:
buildConfiguration: 'Release'
steps:
- script: dotnet restore
- powershell: |
Write-Host "Your parameter is now: $env:Param"
Write-Host "When outputting standard variable build id: $(Build.BuildId)"
Write-Host "When outputting standard variable build id via env: $env:BuildNumber"
Write-Host "The repo name is: $(Build.Repository.Name)"
Write-Host "The build definition name is: $(Build.DefinitionName)"
- script: dotnet build --configuration $(buildConfiguration)
displayName: 'dotnet build $(buildConfiguration)'
- task: DotNetCoreCLI#2
inputs:
command: 'build'
projects: '**/edocs.utils.bluebeam-api.Caller/edocs.utils.CDEComms/edocs.utils.CDEComms.csproj'
So far I have tried several combinations of dir for where azure should locate the build file, however, each time it fails. The solution has several projects within it. CDEComms is the only project within that folder so I'm left quite confused as to what's going on.
I'm quite new to building pipelines and any help as to why this is failing would be greatly appreciated.
In order to narrow down the issue, try to simply specify **/*.csproj in the YAML file to check the build result. And set variable system.debug to True, to check whether the path is correct in C:\hostedtoolcache\windows\dotnet\dotnet.exe build {path}. Also, clone the repo to your local machine to run build it locally, to check the result.
From the description you have provided, you will first have to push your code/solution i.e. the content of your C:\ drive to your repository.
I am extending a Windows application that analyzes C# code and detects various smells. The extension will also work within GitHub Action. The intent is to analyze the committed code as part of CI cycle using this application. The application is a console application based on .NET framework 4.7.2.
To integrate the application with the GitHub Actions, I put together a yml file (produced below). Everything else works fine but the application fails with the following message.
The tools version "15.0" is unrecognized. Available tools versions are "2.0", "3.5", "4.0".
I am using the following yml file. As you may observe, I have added MSBuild to the path, set the environment variable to use version 15, set environment variable VSINSTALLDIR to the Visual Studio 2017 installation, and installed build tools. However, I still get the error. What am I missing?
Name: CI
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
build:
runs-on: windows-latest
steps:
- uses: actions/checkout#v2
# Add MsBuild to the PATH: https://github.com/microsoft/setup-msbuild
- name: Setup MSBuild.exe
uses: microsoft/setup-msbuild#v1.0.0
with:
vs-version: '15.0'
- name: env var
run: echo ::set-env name=VSINSTALLDIR::"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise"
- name: checking sdk
run: echo ::set-env name=VisualStudioVersion::"15.0"
- name: install build tools
run: |
curl.exe -o buildtools.exe https://download.visualstudio.microsoft.com/download/pr/3e542575-929e-4297-b6c6-bef34d0ee648/639c868e1219c651793aff537a1d3b77/vs_buildtools.exe
.\buildtools.exe --quiet --wait --norestart --nocache --add Microsoft.VisualStudio.Workload.ManagedDesktopBuildTools --add Microsoft.VisualStudio.Workload.UniversalBuildTools --add Microsoft.VisualStudio.Workload.MSBuildTools --add Microsoft.VisualStudio.Workload.VCTools
# Runs a set of commands using the runners shell
- name: download DesigniteConsole.exe
run: |
curl.exe -o DesigniteConsole.zip "<download link>"
powershell.exe -nologo -noprofile -command "& { Add-Type -A 'System.IO.Compression.FileSystem'; [IO.Compression.ZipFile]::ExtractToDirectory('DesigniteConsole.zip','.');}"
- name: Run Designite application (it utilizes GitHub secrets and environment variables)
run: |
.\DesigniteConsole\DesigniteConsole.exe -ci -repo ${{github.repository}} -pat ${{ secrets.PAT }} -k ${{ secrets.D_KEY }}
cat Designite_output/DesigniteAnalysis.xml
After so many hit-and-try attempts, I was able to make it run. Here is the working yaml.
Name: CI
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
build:
runs-on: windows-latest
steps:
- uses: actions/checkout#v2
- name: Run a one-line script
run: Invoke-webrequest -uri https://aka.ms/vs/15/release/vs_buildtools.exe -OutFile vs_buildtools.exe
shell: powershell
- name: install build tools
run: .\vs_buildtools.exe --wait --norestart --passive --installPath "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools" --add Microsoft.VisualStudio.Workload.ManagedDesktopBuildTools --add Microsoft.VisualStudio.Workload.MSBuildTools
shell: cmd
# Runs a set of commands using the runners shell
- name: download DesigniteConsole.exe
run: |
curl.exe -o DesigniteConsole.zip "<download link>"
powershell.exe -nologo -noprofile -command "& { Add-Type -A 'System.IO.Compression.FileSystem'; [IO.Compression.ZipFile]::ExtractToDirectory('DesigniteConsole.zip','.');}"
- name: Run Designite application (it utilizes GitHub secrets and environment variables)
run: |
.\DesigniteConsole\DesigniteConsole.exe -ci -repo ${{github.repository}} -pat ${{ secrets.PAT }} -k ${{ secrets.D_KEY }}
cat Designite_output/DesigniteAnalysis.xml
Hope I understood your question correctly.
Check out this issue
https://github.com/microsoft/setup-msbuild/issues/18#issuecomment-644485409
The hosted agents only have latest version of VS on them. The version flag is really there in the event that changes and/or you have self-hosted agents.
or
https://github.com/microsoft/setup-msbuild/issues/5#issue-588501457
Recently the runner has been failing to execute this engine when specifying a version argument.
Workaround: remove any use of vs-version argument for the action and let it default to latest.
I am using Visual Studio 2017 and Azure Dev Ops to run a test on being able to debug a .dll I don't have the source code locally. However, I have run into a problem.
I have a C# .net Standard library with a single class containing a single method in it. I'm using Azure DevOps to do the build for this library. I have created the build pipeline template for an ASP.NET project. The YAML for my build pipeline is as follows:
steps:
task: NuGetToolInstaller#0
displayName: 'Use NuGet 4.4.1'
inputs:
versionSpec: 4.4.1
task: NuGetCommand#2
displayName: 'NuGet restore'
inputs:
restoreSolution: '$(Parameters.solution)'
vstsFeed: 'a1deac36-75b8-4a5c-a86c-26a137db5913'
task: VSBuild#1
displayName: 'Build solution'
inputs:
solution: '$(Parameters.solution)'
msbuildArgs: '/t:restore;build;pack /p:PackageVersion=$(Build.BuildNumber) /p:PackageOutputPath=$(build.artifactstagingdirectory) /p:AssemblyFileVersion=$(Build.BuildNumber)'
platform: '$(BuildPlatform)'
configuration: '$(BuildConfiguration)'
clean: true
msbuildArchitecture: x64
task: PublishSymbols#2
displayName: 'Publish symbols path'
inputs:
SearchPattern: '**\bin\**\*.pdb'
SymbolServerType: TeamServices
continueOnError: true
task: PublishBuildArtifacts#1
displayName: 'Publish Artifact'
inputs:
PathtoPublish: '$(build.artifactstagingdirectory)'
ArtifactName: '$(Parameters.ArtifactName)'
The build creates .dll, .pdb, and .nupkg files. The .pdb appears to be uploaded correctly to the Symbol Server I have access to. I have created a local c# console app project referencing the built .nupkg file. When I run the console app, it says it loaded symbols successfully from the Symbol Server (my Symbol Cache locally has the corresponding .pdb file). However, when I go to step into the method contained in the class in the .dll, I am prompted for the source code file. In my output window in Visual Studio there is the following error:
SRCSRV: The module 'C:\Users\<USER_NAME>\Source\Workspaces\ConsoleApp1\ConsoleApp1\bin\Debug\ClassLibrary1.dll' does not contain source server information.
I have the 'Enable source server support' checkbox checked, along with the top two child checkboxes selected. I also have 'Enable Just My Code' unchecked and 'Enable Source Link support' checked.
I have read over all of the Microsoft docs pages about .pdbs and Azure Dev-Ops and believe I have everything set correctly, but for some reason it still prompts me for the source file instead of being able to use the source server. So am I missing something in my build or somewhere else that would cause this error when trying to step into the compiled code?