How to get Roslyn Analizer results in VSTS Build Definition? - azure-devops

I'm working on DevSecOps. Related to that, I want to secure my application with the help of Roslyn Analyzer. For that I created an MVC Web Application along with custom ruleset in Visual Studio and it's working fine with outputs clearly.
But, when I tried to do same thing with the help of VSTS Build task in my Build Definition in VSTS account. By referring the link, I known that with the help of MSBuild task we can get the Roslyn Analyser results by default. But I didn’t get the results of Roslyn Analyzer results after running my Build Definition. Can you suggest me to “How to overcome this situation”?

If that works locally when run msbuild in command line, then you can try below items to narrow down the issue:
Add a command line task to run the msbuild command line script
directly.
Change another hosted agent.
Deploy an private agent on your dev machine, then check if that works
with the private agent.
You can also reference below articles to troubleshoot the issue:
Using, configuring and distributing Roslyn analysers in teams
Running Code Analyzers on Build Server

Related

Azure devops cant open the code coverage file

Hi guys i have a problem with my code coverage of my azure pipeline. When the CI gets trigged for the master branch the agent has a job to test the .net core. When i use this test i have to configure the route and also enable the code coverage. After the CI has been done it ended succesfully and i can download a file with the code coverage. The problem i have is i cant open this file, not with visual studio or anything else. Aynone that knows how i can fix this problem and maby i didnt configure it right?
Picture of my settings:
picture of the file
picture of the error https://i.stack.imgur.com/fxqdI.png
Seems you are using the wrong configuration. I'm afraid --collect"Code coverage" will not work.
You could add a .NET core test task and add /p:CollectCoverage=true argument then use report generate task for adding code coverage reports.
More detail steps, please refer below tutorials:
ASP.NET Core code coverage reports on Azure DevOps
Azure DevOps, unit testing and code coverage with .Net Core
To generate code coverage please follow this steps
Restore nuget packages
Build the app
Run unit tests (You need to add nuegte package to test projects -> coverlet.collector to use 'XPlat Code Coverage')
Install report generator
Run report generator
Publish code coverage

VssServiceResponseException: Forbidden in Azure Pipelines

I'm using Azure Pipelines to run automated tests via VSTest Platform (V2). The deployment group I'm using has no Internet access and is private. I have the task currently set up to run Nunit tests in the project via the test assemblies. The deployment group has VSTest Platform installed on it and I specify the path to vstest.console.exe in the task. The build artifact is downloaded from the pipeline.
The error I'm getting during the VSTest task is this:
Unhandled exception ocurred: Microsoft.VisualStudio.Services.WebApi.VssServiceResponseException: Forbidden
Followed by a stack trace and then this shortly after:
Error: The process 'C:\agent\A1\_work\_tasks\VSTest_ef087383-ee5e-42c7-9a53-ab56c98420f9\2.164.2\Modules\DTAExecutionHost.exe' failed with exit code 3762504530
I can attach the full log if need be, but I'm just trying to get some general direction at the moment.
First off, what is VssService? I'm assuming it has something to do with Visual Studio, but the only things I can find with the VSS acronym are Visual SourceSafe (Microsoft source control software from ~2005, so I really doubt that's it) and something to do with Cisco network switches.
Second, what is DTAExecutionHost?
Third, where can I find information on that error code?

Visual Studio Online / Azure stopping and starting web applications using Powershell

I'm using Visual Studio Online's build tools to deploy web applications from a single solution. I've occasionally been running into file locking issues.
Error: Web Deploy cannot modify the file 'Microsoft.CodeAnalysis.CSharp.dll' on the destination because it is locked by an external process.
After some Googling, I believe the "fix" is to stop the web applications before deployment on Azure and start it back up after. Sounds legit.
However, there does not seem to be a straight forward way to do this directly on VSO's build definitions. I've created an "Azure Powershell" build task, but it wants a PS1 file from the repository. It doesn't seem to let me just run Azure Powershell commands (e.g. Stop-AzureWebsite) from here. My team has created a work-around where we have a "run.ps1" that just executes the command you pass as a parameter, but none of us are satisfied by that.
What are we missing? There has got to be an easier way to do this without having a PS1 script checked into source control.
I solved this by installing Azure App Services - Start and Stop extension from Visual Studio Marketplace.
When installed, it will allow you to wrap the Deploy Website to Azure task in your Release definition with Azure AppServices Stop and Azure AppServices Start tasks, effectively eliminating the lock issues.
Check if you are using "/" on the "Web Deploy Package" path for folder separators instead of "\".
i.e. change
$(System.DefaultWorkingDirectory)/My Project/drop/MyFolder/MyFile.zip
for
$(System.DefaultWorkingDirectory)\My Project\drop\MyFolder\MyFile.zip
I noticed that was the only difference between the one I was getting the error and the others (the Restart step I added was not helping). Once I modified the path, I got it working.
Sounds crappy, but fixed my issue.
Did you use the Build Deployment Template that sets the correct msbuild parameters for you for your package? You can see how here. I would create a build using that template and see if you have the same issues. If so ping me on Twitter #DonovanBrown and I will see if I can figure what is going on.
As a rule it is good practice to have any scripts or commands required to deploy your software to be checked into source control as part of your build. They can then be easily run repeatedly with little configuration at the build level. This provides consistency and transparency.
Even better is to have deployment scripts output as part of the build and use a Release Management tool to control the actual deployment.
Regardless having configuration as code is a mantra that all Dev and Ops teams should live by.

Get Build Version in automated build deployment using TFS

I am deploying web application to azure using TFS CI automated build deployment.
In our config maintain build version like 2014.05.19.1 which is $(Date).$(rev) format.
All I want to update config each time build is deployed.For that I am passing value to 'BuildVersion' parameter in template to powershell script which actually performs publishing to azure.
I tried using $(Date:yyyyMMdd)$(Rev:.r) but it is considered string as it is.
I want to get current build version just like IBuildDetail.BuildNumber
within template.
My question is how to get the build version?
If you are using Invoke Process, instead of passing value for BuildVersion parameter you can directly use 'BuildDetail.BuildNumber' in parameters for process like
String.Format("-BuildNumber ""{0}""",BuildDetail.BuildNumber)
This would give the required build number.
If your PowerShell script is being executed from your TFS build, it should have access to the environment variables specific to the TFS context of the build. If that is the case, you actually don't need to pass the $(BuildVersion) parameter to the script, as it already is accessible to the PS script in the $env:TF_BUILD_BUILDNUMBER environment variable. Try testing something like $env:TF_BUILD_BUILDNUMBER | Out-File "D:\Dev\BuildNumber.txt" in your script. You should hopefully see the file containing your build number after running your build.
(I am assuming you are using a relatively new build process template...one that contains the "Post-Build script path" parameter, such as TfvcTemplate.12.xaml)
Hope this is helpful.
I would recommend that you use the right tool for the right job. The build system, is really only for building (compile & test). We have been using it for other things for years coz we did not have another integrated solution. However Microsoft recently bought InRelease and rebranded as Release Management for Visual Studio 2013. I have successfully integrated this with TFS 2012 as well.

TFS Manual Mstest Publish Results?

Following a MSDN web page, I am trying to manually run mstest within my tfsbuild.proj and put the results into the pass/fail logic so the build will fail if this particular test fails. It's kind of like running a FxCop or something else from CMD and capturing a "0" or "1" and force-fail the build.
MSTest /testcontainer:test.dll /publish:http://ourtfsmachine:8080 /teamproject:ProjectName /publishbuild:BuildNumber01 /platform:AnyCpu /flavor:Release
I could understand running this inside an Exec task, butI don't know what the BuildNumber is, for example.
Help?
Instructions for getting the Build Number from http://msdn.microsoft.com/en-us/library/ms243151%28VS.100%29.aspx:
Open Visual Studio and connect to a Team Foundation Server.
Open Team Explorer.
Open your team project and expand the team project node.
Under the build, double-click All Build Types or a specific build type to see its builds. Build names that you can use are in the Name column.