CodeAnalysis using msbuild does not fail on warning/error - powershell

I started down this path of wanting to do code analysis on my solution using msbuild. I was looking at FxCop but it appears to now be part of Visual Studio and from my understanding you need Visual Studio installed on your build agents.
I am calling msbuild from a powershell using the following command;
"$(get-content env:systemroot)\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe /tv:4.0 /p:RunCodeAnalysis=Always"
It appears to run the code analysis and output warnings but never fails the build, even after I added <CodeAnalysisTreatWarningsAsErrors>true</CodeAnalysisTreatWarningsAsErrors>
to my .csproj file.
All I want is to run code analysis from msbuild command line and have it fail the build if any warning is found. I understand it can be done in Visual Studio but I need to be able to run this from the command line (with/without VS2013)
Am I missing something? Shouldn't /p:RunCodeAnalysis=Always and setting the CodeAnalysisTreatWarningsAsErrors to true be all that is needed?

Related

How to run Gtest in powershell with set debug environment

Currenlty I am using Visual Studio community edition and Gtest.
When I run my test using the Visual Studio debug, my test are running fine
But when I build the solution and run my test fail.
Is there a way I can pass the PATH environment to the command I am runnig?
Try to set the PATH on powershell so it would load while running the command.
Thanks to #273k I was able to solve my problem.
The reason this test did not pass on the command line, was due to this was being run on a different folder.
Once I moved the relevant support files in the same folder the test started to pass

MSBuild weird behavior when run inside a script

I have some PS scripts that I use for SVN tagging / releasing applications.
Usually its working fine, everything is built as I want to.
Few days ago, I'm told to make a fresh release of some older application.
So I tried leveraging my scripts for that purpose. So far so good.
The problem I'm facing now: Somehow, when MSBuild is called inside my script, its giving me errors
The thing is, when I execute the same command outside the script in a PS console, its building without errors.
The call: C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\msbuild.exe solution.sln /t:Build /p:Configuration=Release /m /v:q /clp:Summary /nologo
Any suggestions are appreciated.
Apparently it has to do with PackageReference on older projects..
https://github.com/dotnet/sdk/issues/8100 my workaround is to build in VS first then use my script without restore or clean.
So I got my release.

Visual Studio test task fails in pipeline but succeeds in test console

I am using Visual studio test task to run all my tests as a part of my build definition.
The options that I have enabled are as attached below:
Now, the problem here is that, some of my tests always fail when I run them from the build pipleine , however all of these test seem to pass when I run them via
vstests console.exe command.
ex: "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow\VSTest.Console" <path to dll>
Does anyone have any clue what could be wrong in here?
Thanks.
Using the Installed by tools installer selection, I would need to see what your tools installation task is doing to provide additional info. Maybe you're not installing a version that is compatible with the tests?
If you don't have a specific need to call out a different test platform version, maybe try using Latest.
OR
Since you're calling ...\Microsoft Visual Studio 14.0\...\VSTest.Console, you may want to select the Visual Studio 2015 option.

Run coverage from visual studio and from command line get different result, how to correct it?

I have a project with unit test, when I right click project and run from visual studio, I got 100% coverage. Please see attachment coveargeA.jpg
The method is CleanUpInProcessExperiments.
but when I run it with command line, then I got 0% coverage, see attachment coverageB.jpg. How can I match command line with directly run from visual studio. in fact, I have few methods other than this one has similar issue Really appreciate for any help.
Here is the command line I used:
C:\Users\yanghx14\AppData\Local\JetBrains\Installations\dotCover04\dotCover.exe cover /TargetExecutable="C:\Program Files (x86)\NUnit 2.6.4\bin\nunit-console.exe" /TargetWorkingDir=C:\xxx\ExpMgmt.Tests\bin\Release /TargetArguments="C:\xxx\ExpMgmt.Tests\bin\Release\ExpMgmt.Tests.dll /framework=4.0 /xml=C:\xxx\ExpMgmt.Tests\bin\Release\ExpMgmt.Tests.dll-results.xml /timeout=20000 /noshadow=true" /Output=c:\xxx\3.dcvr

Is there a way to make the VS Package Manager commands available on Powershell Console?

Is there a way to make the VS Package Manager commands available on Powershell Console? I looked over this link but I was unable to understand the NuGet philosophy.
I know that I can access it in Visual Studio but, let me explain my approach and goal.
I want to learn F# and for this use a lot its REPL. So basicaly, I open a Powershell console, change to my working folder, create a file with some code, fire the REPL, try various things.
In this kind of loop makes sense to have means to install various packages without starting VS and having to create a VS project.
Thanks!
Please refer to below screenshots:
The problem is that the PowerShell cmdlets that NuGet makes available inside Visual Studio rely heavily on Visual Studio so they are not supported outside of Visual Studio from the command line.
From the command line you have NuGet.exe which supports the following which are project related:
Downloading NuGet packages. Basically restoring the missing NuGet packages as defined in a packages.config file. NuGet.exe install or NuGet.exe restore
Updating a NuGet package in a project. This will update the reference information but not run PowerShell scripts. NuGet update
Having the NuGet PowerShell cmdlets available on the command line is something I have looked at doing using the cmdlets that SharpDevelop provides. It is possible to fully support NuGet install/update/uninstall and have the PowerShell scripts execute on the project but in this case it requires an entire IDE, in this case SharpDevelop, to be available, at least its assemblies, even though the IDE is not run. This is needed to support updating the project file using the Visual Studio project model (EnvDTE) from within any PowerShell scripts that run.
Nuget commands cannot be used outside of Visual Studio. However, if you were change to use Paket instead of Nuget, then you can use Paket from a command line outside of Visual Studio to manage your project's packages.
The getting started page is here.