I'm setting up the CI/CD for my .Net core project.
I have configured for the only build stage which is failing with below error message:
"MSBUILD : error MSB1003: Specify a project or solution file. The
current working directory does not contain a project or solution
file."
My solution structure is different. Project .SLN file is inside another folder its not available working directory.
My .SLN file is in Solution folder.
My solution structure image path:
Here my gitlab-ci.yml code looks like:
stages:
- build
before_script:
- 'dotnet restore'
build:
stage: build
script:
- dotnet build Solution/MyApp360.sln
only:
refs:
- master
- release
- develop
What I am missing here?
Am I passing the SLN file path wrongly?
How to pass the .SLN path to the build command.
Any example is appreciated.
If you are running your jobs on Windows in cmd executor, then you need to write your paths with '\' instead of '/'. The line would then be:
dotnet build Solution\MyApp360.sln
Related
I have the following build script which is not working with Azure Devops Build Pipelines. After Building the solution, I am trying to delete a specific DLL from the bin folder which works locally but not in the build pipeline.
<PropertyGroup>
<PostBuildEvent>
cd $(TargetDir)
del Sample.dll
</PostBuildEvent>
</PropertyGroup>
Build Solution Definition
steps:
- task: VSBuild#1 displayName: 'Build solution' inputs:
solution: '$(Parameters.solution)'
vsVersion: 15.0
msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=false /p:SkipInvalidConfigurations=true /p:PackageLocation="$(Build.ArtifactStagingDirectory)\\" /p:Configuration=Release'
platform: '$(BuildPlatform)'
configuration: '$(BuildConfiguration)'
maximumCpuCount: true
Delete
steps:
- task: DeleteFiles#1
displayName: 'Delete files from $(Build.ArtifactStagingDirectory)'
inputs:
SourceFolder: '$(Build.ArtifactStagingDirectory)'
Contents: |
\Sage.Common.LinqBridge*\
\Sage.Common.LinqBridge.dll*\
Publish
steps:
- task: PublishBuildArtifacts#1
displayName: 'Publish Artifact'
inputs:
ArtifactName: '$(Parameters.ArtifactName)'
condition: succeededOrFailed()
Solution:
Thank you #Levi Lu-MSFT in helping me with the solution.
In the delete task, changing the delete pattern worked. For reference,
steps:
- task: DeleteFiles#1
displayName: 'Delete files from $(Build.ArtifactStagingDirectory)'
inputs:
SourceFolder: '$(Build.ArtifactStagingDirectory)'
Contents: '**\Sage.Common.LinqBridge.dll'
Remove a DLL from the bin folder in the Build Pipeline
I have created a sample to test, and it works fine on my side.
To resolve this issue, I would like provide following trouleshootings:
Check the build log, to found out if the PostBuildEvent is executed successfully.
Make sure you have specify the correct MSBuild arguments in the build task, like: /property:Configuration=Release:
If you are using the private agent, make sure you have permission to delete file from the private agent. Or you can test it with hosted agent.
Update:
According to the error log, we could to know you are publishing the project and delete the one .dll file in the post build event.
If you check the log, you will find MSBuild get the files from the folder obj\Release\Package\PackageTmp\bin rather than bin folder. That is the reason why the Sage.Common.LinqBridge.dll still exists after you delete it.
Check the log:
Adding file (d:\a\8\s\xx\xxx\xxx\xxx\obj\Release\Package\PackageTmp\bin\Sage.Common.LinqBridge.dll)
And you could not delete that file in the .zip by the delete task.
To resolve this issue, you could set Copy Local to False for that dll file.
Update2:
After talk with mbharanidharan88, found the reason for this issue is that not use correct syntax in the contents in the delete task.
To delete the file only in the bin folder, we could use the following syntax:
**\bin\Sage.Common.LinqBridge.dll
Hope this helps.
I seriously need help to create my yml build file because I cannot find any good tutorial, sample or other king of help anywhere. I always get similar error: See the warning, it seems my build artifact is always empty. All step are succes but I cannot deploy because my files are not found. Stupid.
##[section]Starting: PublishBuildArtifacts
==============================================================================
Task : Publish Build Artifacts
Description : Publish build artifacts to Azure Pipelines/TFS or a file share
Version : 1.142.2
Author : Microsoft Corporation
Help : [More Information](https://go.microsoft.com/fwlink/?LinkID=708390)
==============================================================================
##[warning]Directory '/home/vsts/work/1/a' is empty. Nothing will be added to build artifact 'drop'.
##[section]Finishing: PublishBuildArtifacts
Here is my pipeline definition
# ASP.NET Core
# Build and test ASP.NET Core projects targeting .NET Core.
# Add steps that run tests, create a NuGet package, deploy, and more:
# https://learn.microsoft.com/azure/devops/pipelines/languages/dotnet-core
trigger:
- master
pool:
vmImage: 'Ubuntu-16.04'
variables:
buildConfiguration: 'Release'
steps:
# - script: dotnet build --configuration $(buildConfiguration)
# displayName: 'dotnet build $(buildConfiguration)'
- task: DotNetCoreInstaller#0
inputs:
version: '2.2.202' # replace this value with the version that you need for your project
- script: dotnet restore
- task: DotNetCoreCLI#2
displayName: Build
inputs:
command: build
projects: '**/*.csproj'
arguments: '--configuration Release' # Update this to match your need
- task: PublishBuildArtifacts#1
inputs:
ArtifactName: 'drop'
Note the 2 line I commented
# - script: dotnet build --configuration $(buildConfiguration)
# displayName: 'dotnet build $(buildConfiguration)'
are in fact part of the default script. I'm not using the default script. I'm following the tutorial https://learn.microsoft.com/en-us/azure/devops/pipelines/languages/dotnet-core?view=azure-devops
Also why I cannot use the templates available for my other projects. Is it because I'm using DevOps repository or because my project has specific settings? I have other project I can manage the build then deployment with graphical template and task. A lot more easier.
Yes, help on yaml pipelines seem a bit scattered and thin on the ground at the moment.
Since your project is AspNetCore, I think what you're missing is the dotnet publish task, after the build task and before the PublishArtifacts:
- task: DotNetCoreCLI#2
inputs:
command: publish
publishWebProjects: True
arguments: '--configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)'
zipAfterPublish: True
But here are steps I have been through trying to resolve frustration with netcore yaml pipelines:
You have already looked through the guide's example tasks & snippets at
Build, test, and deploy .NET Core apps ?
You have noticed that you can click on the build log to see the detailed output of each step in your pipeline?
You have noted that the task DotNetCoreCLI#2 is equivalent to running dotnet <command> on your own desktop so you can to some extent run/debug these tasks locally?
I found Predefined Variables gave some helpful clues. For instance it tells us that the path \agent\_work\1\a is probably the $(Build.ArtifactStagingDirectory) variable, so that helped me in mimicking the pipeline on my local machine.
Logically, your error message tells us that $(Build.ArtifactStagingDirectory) is empty when the pipeline reaches the last step. The dotnetcore example page suggests to me that publish is the task that populates it for a web project. For anything else, I think just the dotnet build task is enough.
Just replace in variables:
**/Dockerfile
…by
$(Build.SourcesDirectory)/Dockerfile
That works for me.
I have a question about workflow with docker and gitlab-ci or automated builds in general.
This is how I am imagine how a build should look like↓.
How to do it with gitlab-ci ?
I know how to do one of this tasks, but I don't know how to.
In my imagination i would need more than one base image.
Maybe I am missunderstanding the hole thing.
How should this process be done in general ?
Thx four your help 😀
Since your question is very general, I will answer it with an example.
Consider a imaginary C++ project, which contains the code, a Makefile which creates the executable "app" and this Dockerfile:
FROM ubuntu:16.04
ADD ./app /app
CMD ["/app"]
To build the application and the docker image as you said, you could use a GitLab CI config like this:
stages:
- test
- build
- docker
test:
stage: test
script:
- make test
build:
stage: build
script:
- make
artifacts:
paths:
- ./app
docker:
stage: docker
dependencies:
- build
script:
- docker build -t your-repo/image-name:latest .
- docker push your-repo/image-name:latest
Explanation
This CI file creates three jobs: "test", "build" and "docker". "test" runs "make test" to execute any imaginary tests our codebase might have. If they suceed, the GitLab runner will execute the next job, "build".
"build" builds the application by calling "make". We expect make to create a file "app" in the current directory, which is our compiled application that will run in the container. The section "artifacts" states that we want to keep this resulting file, since we need it for the next job.
The next job "docker" has a section "dependencies"; in this section we state that this job depends on the output of the job called "build", which created our file "app" before. Then we first build the docker image using docker build and push it as usual.
As said before, these are just examples, and especially the script sections will greatly differ based on your projects and your runner config. See the official CI documentation for all possibilities.
I was trying to configure a simple pipeline to build and deploy my asp.net core application into shared hosting, however it always failed in restoring Newtonsoft.Json, dispute the project is build-able and fully works on local machine, my ci file looks like the following:
image: microsoft/dotnet:latest
stages:
- build
before_script:
- dotnet restore -s https://api.nuget.org/v3/index.json --packages ./.nuget/
build:
stage: build
script:
- "dotnet build"
And the error I am getting inside the pipeline is:
/usr/share/dotnet/sdk/2.1.402/Microsoft.Common.CurrentVersion.targets(2110,5): warning MSB3245: Could not resolve this reference. Could not locate the assembly "Newtonsoft.Json". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.
I also tried dotnet restore only, but with the same result.
I figure out the problem, I added the Newtonsoft.Json as reference instead of installing it from nuget (actually visual studio added it as reference for me from the quick action), so I remove the reference and install it as package and everything works perfectly
I have a Visual Studio Online build definition that seems to be misbehaving, but I'm not sure if I've just misconfigured something.
There is a build step which is configured as follows:
Type: Visual Studio Build
Solution: **\mysolutionfile.sln
MSBuild Arguments: /p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.stagingDirectory)"
The build runs successfully, and the build log shows the msbuild command is executed as follows:
"C:\Program Files (x86)\MSBuild\14.0\bin\msbuild.exe" "C:\a\1\s\Code\mysolutionfile.sln" /nologo /nr:false /dl:CentralLogger,(more removed for brevity) /p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="C:\a\1\a" /p:platform="any cpu" /p:configuration="release" /p:VisualStudioVersion="14.0" /p:_MSDeployUserAgent="VSTS_6efdabeb-1c75-43a7-96b2-f40e19a68a35_build_14_122"
As you can see, the package location is correctly set: /p:PackageLocation="C:\a\1\a"
However, later in the build log, the package step shows this log entry:
2017-01-20T05:07:30.9771422Z Executing command ["C:\Program Files (x86)\IIS\Microsoft Web Deploy V3\msdeploy.exe" -source:manifest='C:\Users\buildguest\AppData\Local\Temp\PublishTemp\obj\mysolution55\SourceManifest.xml' -dest:package='C:\a\1\s\Code\mysolutionfile\bin\Release\MSDeployPackage\mysolutionfile.zip' -verb:sync -replace:match='C:\\Users\\buildguest\\AppData\\Local\\Temp\\PublishTemp\\mysolutionfile55\\',replace='website\' -retryAttempts:20 -disablerule:BackupRule]
As you can see, in this case the package is being sent to -dest:package='C:\a\1\s\Code\mysolutionfile\bin\Release\MSDeployPackage\mysolutionfile.zip' - and this is indeed where the zip file ends up.
As far as I can tell, this looks wrong. I want to have the packaged application binaries and files end up in the staging directory, but msbuild is overriding me somewhere and putting them into the source checkout folder.
In case it's relevant, the solution contains two projects: an ASP.NET Core web app that is targeting the full .NET Framework; and a portable class library.
Am I doing something wrong in the build configuration?
I reproduced your issue in my TFS Environment and I got the same result with. The package under the "C:\a\1\s" folder not "C:\a\1\a'.
As a workaround, you could add a Copy files step to copy the package from the source folder to $(build.stagingDirectory) path.
I guess that it did not work as you expected because the variable name should be Build.ArtifactStagingDirectory instead of build.stagingDirectory
Example:
- task: VSBuild#1
inputs:
solution: '$(solution)'
msbuildArgs: '/p:Configuration=Release /p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(Build.ArtifactStagingDirectory)"'
#msbuildArgs: '/T:"MyProject1" /p:OutDir=$(Build.ArtifactStagingDirectory) /nowarn:FS0049'
- task: PublishBuildArtifacts#1
inputs:
pathtoPublish: '$(Build.ArtifactStagingDirectory)'
artifactName: MyWebSiteArtefactZIP
There is also another way to Deploy:
If you have created a Publish Profile (you can use Visual Studio for that),
it is also possible to Publish directly from MSBuild, you can put the Web App username/password in the Azure DevOps Pipeline variables and use them:
- task: VSBuild#1
inputs:
solution: '$(solution)'
msbuildArgs: '/p:Configuration=Release /P:DeployOnBuild=true /P:PublishProfile="MyPublishProfile.pubxml" /P:Username=$(username);Password=$(password)'