I have found a docker image with msbuild and nuget installed. I want to use msbuild to build my .NET framework project, but it returns the following error:
$ & "$env:MSBUILD_PATH" /p:Configuration=Release /clp:ErrorsOnly
& : The term 'C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\MSBuild.exe' is not
recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if
a path was included, verify that the path is correct and try again.
At line:1 char:3
+ & "$env:MSBUILD_PATH" /p:Configuration=Release /clp:ErrorsOnly
+ ~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (C:\Program File...Bin\MSBuild.exe:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Here is my yaml file:
.shared_windows_runners:
tags:
- shared-windows
- windows
- windows-1809
variables:
MSBUILD_PATH: 'C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\MSBuild.exe'
NUGET_PATH: 'C:\Nuget\nuget.exe'
stages:
- build
build:
extends:
- .shared_windows_runners
stage: build
image: compulim/msbuild
script:
- echo "start building"
- '& "$env:MSBUILD_PATH" /p:Configuration=Release /clp:ErrorsOnly'
- '& "$env:MSBUILD_PATH" WebCICD\WebCICD.csproj /p:DeployOnBuild=true /p:Configuration=Release /P:PublishProfile=FolderProfile.pubxml'
- Tree
I found this docker image by googling "docker msbuild image".
I thought the image could let me use the file path to build the project directly. Am I wrong?
Is there anything I am missing?
Thanks
Related
I am running a simple hello world python program in gitlab ci. While running it in pipeline it throws the error python not used as the name of a cmdlet.
here is my yml file
workflow:
rules:
- if: $CI_PIPELINE_SOURCE == "push"
when: always
stages:
- Test
- Build
Test_stage:
tags:
- PC_RUNNER
stage: Test
script:
- echo "Test stage started"
- cd .\test\test
- python hello.py
and here is the error
$ cd .\test\test
$ python helloworld.py
python : The naming "python" was not used as the name of a cmdlet, function, script file, or executable
program recognized. Check the spelling of the name, or if the path is correct (if included), and
repeat the process.
In C:\WINDOWS\TEMP\build_script3952941328\script.ps1:235 characters:1
+ python helloworld.py
+~~~
+ CategoryInfo : ObjectNotFound: (python:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
But when i change the command and give the full path where my python is installed it works
script:
- echo "Test stage started"
- cd .\test\test
- C:\users\abc\python\python.exe hello.py
I have added the environmental paths correctly as i have already double checked it. From the Gitlab documentation i came to know that we can also add environment variable in gitlab runner TOML file which i did as follows
executor = "shell"
shell = "powershell"
environment = ["ENV=C:\users\abc\python\", "LC_ALL=en_US.UTF-8"]
But the gitlab pipeline still throws the above error. Does someone knows what am i doing wrong here? Thanks in advance
This is really bizarre, but I'm sure I'm misunderstanding or missing something simple.
Whilst RDP'd to the Windows GitLab runner, the following command works without issue:
"C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\MSBuild\Current\Bin\MSBuild.exe" C:\GitLab-Runner\builds\rS1z3GJ3\0\folder1\client\build\ClientWebsite.msbuild /t:BuildAndPackage /nowarn:CS0618 /p:IisWebAppName=client /p:IncludeSetAclProviderOnDestination=False /p:ProductVersion=1
Going by the MSBuild file, the build files are then created under C:\GitLab-Runner\builds\rS1z3GJ3\0\folder1\client\deploy_files.
But when I run the exact same command in via the gitlab-ci.yml file, the deployment files aren't generated.
The output from the GitLab job is:
CMD.EXE "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\MSBuild\Current\Bin\MSBuild.exe" C:\GitLab-Runner\builds\rS1z3GJ3\0\folder1\client\build\ClientWebsite.msbuild /t:BuildAndPackage /nowarn:CS0618 /p:IisWebAppName=client /p:IncludeSetAclProviderOnDestination=False /p:ProductVersion=1
Microsoft Windows [Version 10.0.17763.2628]
(c) 2018 Microsoft Corporation. All rights reserved.
C:\GitLab-Runner\builds\rS1z3GJ3\0\folder1\client>
Cleaning up project directory and file based variables 00:00 Job succeeded
I thought perhaps this was an issue with the user the GitLab Runner service was set to run as, but even when trying with a local admin user it still doesn't work.
I suspected it was an issue with the cleaning up of the project directory, but even when setting the deployment files to be exported to a separate folder on another drive they still don't appear.
What could I be doing wrong?
Any help with this would be greatly appreciated.
EDIT:
GitLab Runner Config:
concurrent = 1
check_interval = 0
[session_server]
session_timeout = 1800
[[runners]]
name = "buildserver01"
url = "https://gitlab.company.co.uk"
token = "rS1z3GJ392utu-J-CkeM"
executor = "shell"
shell = "powershell"
[runners.custom_build_dir]
[runners.cache]
[runners.cache.s3]
[runners.cache.gcs]
[runners.cache.azure]
GitLab-Ci.Yml File:
variables:
SERVICE_NAME: "client"
NODE_VERSION: "14.15.3"
stages:
- build $SERVICE_NAME package with MSBuild.exe
build_package:
stage: build $SERVICE_NAME package with MSBuild.exe
tags:
- client
script:
- echo "Installing NodeJS environment $NODE_VERSION if it's not already installed."
- nvm install $NODE_VERSION
- echo "Selecting NodeJS environment $NODE_VERSION using NVM"
- nvm use $NODE_VERSION
- echo "Creating the Web Deploy Package"
- CMD.EXE "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\MSBuild\Current\Bin\MSBuild.exe" C:\GitLab-Runner\builds\rS1z3GJ3\0\folder1\client\build\clientWebsite.msbuild /t:BuildAndPackage /nowarn:CS0618 /p:IisWebAppName=client /p:IncludeSetAclProviderOnDestination=False /p:ProductVersion=1
Thanks to GitLab Support, this has now been resolved.
They advised to completely remove the 'CMD.EXE' command and instead run MSBuild directly via PowerShell:
'& "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\MSBuild\Current\Bin\MSBuild.exe" $CI_PROJECT_DIR\build\ClientWebsite.msbuild /t:BuildAndPackage /nowarn:CS0618 /p:IisWebAppName=Client /p:IncludeSetAclProviderOnDestination=False /p:ProductVersion=1'
I started using Gitlab CI/CD and it is my yml file:
variables:
EXE_LOCAL_TEMP_FOLDER: 'c:\TMP'
DEPLOY_FOLDER: 'c:\MyProject_Release'
stages:
- build
- deploy
build:
stage: build
script:
- nuget restore
- msbuild MySolution.sln /t:Build /p:Configuration=Release
- xcopy /y MyProject\bin\Release\*.* $EXE_LOCAL_TEMP_FOLDER\
deploy:
stage: deploy
when : manual
script:
- xcopy /y c:\TMP\*.* $DEPLOY_FOLDER\
Now I need to deploy a Windows Service(WinService.csproj in my solution) on a remote machine, How can I do it in my yml file?
I'm using gitlab and in the root of my repository, I have a Level4UI project, I want to copy the binary files into a temporary directory after build completed.
So, I defined the following .gitlab-ci.yml file in my GitLab repository:
variables:
EXE_RELEASE_FOLDER: '.\Level4UI\bin\Release2'
EXE_LOCAL_TEMP_FOLDER: 'c:\NewLevel4'
stages:
- build
build:
stage: build
script:
- nuget restore
- msbuild MySolution.sln /t:Build /p:Configuration=Release
- 'xcopy /y $env:EXE_RELEASE_FOLDER\*.* $env:EXE_LOCAL_TEMP_FOLDER\'
When the build completes, I get following error:
File not found - .
0 File(s) copied
ERROR: Job failed: exit status 4
Where is the problem?
You don't need an $env to use your variables in a script section, just use them like this:
- 'xcopy /y $EXE_RELEASE_FOLDER\*.* $EXE_LOCAL_TEMP_FOLDER\'
I have a vue spa application that I host in azure. However, I am not able to get it running as a build pipeline after setting it up in Azure DevOps
The npm install and npm run build work perfectly, however, the script to copy my dist directory to my blob store fails.
Here is what I tried and the results. Does anyone have experience with this?
AzureFileCopy
- task: AzureFileCopy#3
inputs:
SourcePath: '$(System.DefaultWorkingDirectory)/dist'
azureSubscription: '[my subscription details]'
Destination: 'AzureBlob'
storage: 'mystorageaccountname'
ContainerName: '$web'
Result
##[section]Starting: AzureFileCopy
==============================================================================
Task : Azure file copy
Description : Copy files to Azure Blob Storage or virtual machines
Version : 3.1.11
Author : Microsoft Corporation
Help : https://learn.microsoft.com/azure/devops/pipelines/tasks/deploy/azure-file-copy
==============================================================================
##[command]Import-Module -Name C:\Program Files\WindowsPowerShell\Modules\AzureRM\2.1.0\AzureRM.psd1 -Global
##[warning]The names of some imported commands from the module 'AzureRM.Websites' include unapproved verbs that might make them less discoverable. To find the commands with unapproved verbs, run the Import-Module command again with the Verbose parameter. For a list of approved verbs, type Get-Verb.
##[warning]The names of some imported commands from the module 'AzureRM' include unapproved verbs that might make them less discoverable. To find the commands with unapproved verbs, run the Import-Module command again with the Verbose parameter. For a list of approved verbs, type Get-Verb.
##[command]Import-Module -Name C:\Program Files\WindowsPowerShell\Modules\AzureRM.Profile\2.1.0\AzureRM.Profile.psm1 -Global
##[command]Add-AzureRMAccount -ServicePrincipal -Tenant *** -Credential System.Management.Automation.PSCredential -EnvironmentName AzureCloud
##[command] Set-AzureRmContext -SubscriptionId dc6a0ce7-adcd-49fd-ad85-e1c082994145 -TenantId ***
Uploading files from source path: 'D:\a\1\s\dist' to storage account: 'mystorageaccountname' in container: '$web' with blob prefix: ''
##[command] & "AzCopy\AzCopy.exe" /Source:"D:\a\1\s\dist" /Dest:"https://mystorageaccountname.blob.core.windows.net/`$web" /#:"D:\a\_temp\ead7e7cf-0b6e-4b16-928f-c84cf3e3a7ab" /XO /Y /SetContentType /Z:"AzCopy" /V:"AzCopy\AzCopyVerbose_ae491d97-a7a8-44e6-b7b0-4b932a5e6c08.log" /S
[2019/06/13 00:31:08][ERROR] Error parsing source location "D:\a\1\s\dist": Failed to enumerate directory D:\a\1\s\dist\ with file pattern *. The system cannot find the path specified. (Exception from HRESULT: 0x80070003) For more details, please type "AzCopy /?:Source" or use verbose option /V.
##[error]Upload to container: '$web' in storage account: 'mystorageaccountname' with blob prefix: '' failed with error: 'AzCopy.exe exited with non-zero exit code while uploading files to blob storage.' For more info please refer to https://aka.ms/azurefilecopyreadme
##[section]Finishing: AzureFileCopy
Thanks to the comment suggesting I run a "dir". It actually didn't work. Upon inspection, the following command was not even building the app.
- script: |
npm install
npm run build
dir
displayName: 'npm install and build'
I presume this is because I changed the agent to run on windows (I discovered earlier that AzureFileCopy only runs on windows) and windows agent does not allow stacked scripts the way the ubuntu agent does. So I split the install and build into separate tasks and now it runs with only verb warnings. Here is the working script:
pool:
vmImage: 'vs2017-win2016'
steps:
- task: NodeTool#0
inputs:
versionSpec: '10.x'
displayName: 'Install Node.js'
- script: |
npm install
displayName: 'npm install'
- script: |
npm run build
displayName: 'npm run build'
- script: |
dir
displayName: 'list cwd contents (verify build)'
- task: AzureFileCopy#3
inputs:
SourcePath: '$(System.DefaultWorkingDirectory)/dist'
azureSubscription: '[my subscription details]'
Destination: 'AzureBlob'
storage: 'mystorageaccountname'
ContainerName: '$web'