Visual Studio Online Pre-Build step failing - visual-studio

I'm using Visual Studio Online for CI. I have a Release build set up. One of my projects has a pre build step which should only be executed for Debug builds.
if $(ConfigurationName) == Debug copy "$(ProjectDir)Config\web.$(Username).config" "$(ProjectDir)\runtime.config"
However VSO fails the build with an error that the command exited with a status of 1.
The same build runs fine when executed using Visual Studio on a developers machine.

The issue was down to needing brackets on the condition check. Therefore the following works on VSO.
if ($(ConfigurationName) == Debug) copy "$(ProjectDir)Config\web.$(Username).config" "$(ProjectDir)\runtime.config"
The brackets are not required for VS2013.

The command must be between parentheses, because is parsed by CMD.EXE
if $(ConfigurationName) == Debug (
copy "$(ProjectDir)Config\web.$(Username).config" "$(ProjectDir)\runtime.config"
)
See "if".

Related

Is it possible to run a postbuildevent in an Azure Devops .yaml pipeline build event containing macros such as $(TargetPath)?

I'm trying to automatically rename the .dll resulting from VSBuild so it includes the version number. In order to do this I've tried to create a postbuild event in DevOps.
- task: VSBuild#1
inputs:
solution: '$(solution)'
msbuildArgs: '/p:PostBuildEvent="rename $(TargetPath) $(TargetDir)$(TargetName).$(buildNumber)$(TargetExt)"'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
This post build event works fine when I put it in Visual Studio and run it locally. However, I don't want users to be able to change it, so I don't want to define it in Visual Studio but in the pipeline(.yaml) itself. On DevOps I get the following result:
PostBuildEvent:
rename $(TargetPath) $(TargetDir)$(TargetName).20221003.8$(TargetExt)
The system cannot find the file specified.
##[error]C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(5707,5): Error MSB3073: The command "rename $(TargetPath) $(TargetDir)$(TargetName).20221003.8$(TargetExt)" exited with code 1.
It seems as though the postbuild event macros, such as $(TargetPath), which are recognized in Visual Studio are not recognized when running the post build event through DevOps pipelines. Is this correct? If so, is there any way around it? I'd prefer not to hardcode anything since I want to reuse the pipeline for multiple repos/solutions with a variable number of projects and project names.
Thanks a lot!

Post build event not working with msbuild

I have a solution that references multiple projects. In one of those referenced project I added the following Post-Event (to copy it's .exe file to the solution output).
xcopy /y "$(TargetName).*" "$(SolutionDir)UIBackendSSRSReports\$(OutDir)"
This works perfectly when compiling from Visual Studio, but when running from msbuild it fails (exited with code 4).
Seems like when using msbuild the values of OutDir (as well as the other macros) are different.
ex: $(OutDir)
In VS = D:\Workspace-ET\source_SSRSBackEnd\Common\BackEnd Automation\BackEndSSRSReports\UIBackendSSRSReports\bin\Debug
In msbuild = " D:\B\1\Src_PMC-QA-Automation\BackEndSSRSReports_ssrsBranch\bin\
Not sure why they are so different, any ideas? We build with a buildAgent and buildController TFS setup

Build failure in Jenkins after failed test MSTest

In Jenkins I create a Visual studio project using MSBuild. After the build I execute a windows batch command that executes the tests en sets the output file.
Post build I publish the .trx test report file. This all works perfect, the only problem is that if a test fails the build fails. With other types of projects if a test fails the build only becomes unstable.
How can I do the same for my Visual studio project?
Below my batch command:
"C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\MSTest.exe" /testcontainer:TestAppTests\bin\Debug\TestAppTests.dll /resultsfile:TestResults.trx
I know it's pretty old but here are something as I've encountered the same type of problem.
Using Batch:
At the end of that batch command step where you run the tests, add one more exit command, such as exit /b 0 or exit 0.
Using Powershell:
At the end of the powershell command step where you run the tests, same, manually set the exit code $LastExitCode = 0.
Final:
The result will always be set to success no matter how many tests failed so you need to parse and analyze the result yourself. There are tools such as: https://plugins.jenkins.io/mstest and https://plugins.jenkins.io/xunit.

Running devenv.com displays a popup dialog and hangs TeamCity build

My end goal is to run a devenv.com command from a TeamCity build configuration but it's currently hanging when it reaches the deploy stage. If I run the same command from the command line on the build agent server I get a popup at the point when it reaches the deploy stage.
Should state that the solution is a mixture of VSeWSS and WSPBuilder projects for creating .wsp solution files for WSS 3.0.
The command is
"C:\Program Files (x86)\Microsoft Visual Studio
9.0\Common7\IDE\devenv.com" "C:\b\work\807e2e3b4b06ef27\mySolution.sln" /deploy Release /package
The dialog that gets displayed is:
If I hit OK in this dialog, I then get this one:
I assume it's hanging in the TeamCity build because the dialog is stopping the process. I was under the impression though that running "devenv.com" would prevent any UI elements from being shown.

How to call Nunit from Visual Studio in a batch file

I have set my Visual Studio to start Nunit as an external program to run all the tests written in a module.
Now what I am trying to do is to create a batch file which will call Myproj.exe. What I am expecting is that it will run Nunit as I have set it to run an external program and execute all my tests in nunit.exe, but when I run that batch file it starts running from Visual Studio instead of opening NUnit.
Can any one please give me a clear idea as how to accomplish it?
I am too much stuck.
Now I am trying to run the following commands in shell
nunit-x86.exe
Can you please tell how should I load my visualbasic project file (exe) here and then run all the tests from here
as unable to execute following command
nunit nunit.tests.vbproj /config:release
You can make NUnit start everytime you debug your "NUnit tests".
You can attach the debugger in Visual Studio Express doing it that way.
If you use a "full version" of VS do it that way:
Note that if you’re using the full and
not the express version of Visual
Studio 2005, you can do this by
opening up the project’s properties,
and in the Debug tab select Start
External Program: and navigate to the
NUnit executable, and set
YourCompanyname.YourProject.Test.dll as the
Command Line Arguments.
I got that ideas from this tutorial(Page 4/5) and love it.
You can also run NUnit after every successful build in Visual Studio with a Post-Build Event.
In VS2005, right-click on the project that has your tests and select Properties. Then on the Build Events tab, in the "Post-build event command line", put this* to use the console:
nunit-console /xml:$(ProjectName).xml $(TargetPath)
or this to use the GUI::
nunit $(TargetPath) /run
In "Run the post-build event:", leave the default: "On successful build"
If you use the GUI, know that your build will appear to be hung up until you close the GUI app.
*NOTE: The nunit console command line docs say "By default the nunit-console program is not added to your path."
you can just shell nunit.exe with the command line to your assembly to run tests in.
You can load nUnit.exe (nUnit-Console.exe for command line execution) using external tool features in Visual studio. Once you add the command via external tools feature (as explained in this blog), you can use it for any project to execute the tests. (Other is to add through project properties but that needs to be done for every project). Also in the arguments you can pass /include or /exclude to include or exclude categories of the tests.
The advantage of this method is you need not worry about giving path to DLL file and it works for any project you are on and gets executed with few clicks

Resources