Run a command in ccnet.config - command

I am trying to run the nuget command that I would normally set in the projects post build $(ProjectDir)nuget\pack.bat $(ProjectDir) $(TargetDir) $(ConfigurationName) $(SolutionDir) to run instead in the ccnet.config on a successful build. What I have does not seem to be running at all.
<exec>
<Target>
<executable>cmd</executable>
<buildArgs>/C c:\build\project\nuget\pack.bat c:\build\project\ c:\build\project\bin\nuget\ Nuget c:\build\project\ /M</buildArgs>
</Target>
</exec>
Edit
Figured it out partially. Needed to make sure I was pointing to <executable>c:\Windows\System32\cmd.exe</executable> and not using cmd.

Related

vstest console output verbosity switch ignore by MSBuild

We are trying to reduce the console verbosity of our test runs in our Azure DevOps pipelines.
Due to the number of tests and complexity, we wrapped the VSTest.Console.exe run in MSBuild targets.
We configured our vstest.console.exe runs with the /logger:console;verbosity=minimal. When running the vstest command manually through command prompt this works fine, it only outputs the skipped tests and the end result summary, as intended.
When executed through MSBuild targets, even with the simplest target we confirmed, the output to the console is the full VSTest console output as if its in normal verbosity.
We are also setting the MSBuild verbosity to minimal, but this has no effect on the VSTest output.
Here is the target which we can reproduce it with
<Target Name="RunTestWorker" Outputs="$(VSTestConsoleExitCode)">
<Exec Command=""C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\..\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe" "ProjectA.SpecflowTest.dll" /Platform:x64 /logger:console;verbosity=q /logger:trx;LogFileName=TestTrxFile.trx"
ContinueOnError="True"
WorkingDirectory="$(TestResultsDirectory)..">
</Exec>
</Target>
Executed with this MSBuild call:
"C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\amd64\MSBuild.exe" "TestBuild.targets" /verbosity:m /t:RunTestWorker
We tried additional MSBuild Exec options like ConsoleToMSBuild and EchoOff, but this didn't really change much.
Is this a known issue?
This example from Microsoft's docs wraps the arguments after /logger: in quotes:
vstest.console.exe Tests.dll /logger:"console;verbosity=minimal"
I tried this from the command line without the trx logger and it did reduce logging compared to normal.
So in your case:
/logger:"console;verbosity=quiet" /logger:"trx;LogFileName=TestTrxFile.trx"

GoCD Nuget issue

I have a project and my agent does have nuget installed - Not sue what I am doign wwong
12:01:14.195 [go] Start to build DemoApp/20/second/1/secondJob on vivians-mbp-2.delta.rl.delta.com [/Users/vivianaranha/Library/Application Support/Go Agent]
12:01:14.195 [go] Current job status: passed.
12:01:14.195 [go] Start to execute task: <exec command="nuget restore packages.config -PackagesDirectory ..\..\packages" workingdir="EMApp\EMApp\EMApp.iOS" />.
12:01:14.199 Error happened while attempting to execute 'nuget restore packages.config -PackagesDirectory ..\..\packages'.
Please make sure [nuget restore packages.config -PackagesDirectory ..\..\packages] can be executed on this agent.
12:01:14.199 [Debug Information] Environment variable PATH: /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Frameworks/Mono.framework/Versions/Current/Commands:/usr/local/bin
12:01:14.206 [go] Current job status: failed.
Have you tried setting the build details to be more verbose? Also, from when i do it I have the build use the nuget.exe saved in the source control, not on the build agent
You are making a common mistake in GoCD expecting exec task to be a shell execution.
By that build log, I can tell that your configuration in xml is
<exec command="nuget restore packages.config -PackagesDirectory ..\..\packages" workingdir="EMApp\EMApp\EMApp.iOS">
</exec>
That means GoCD would be trying to execute a file whose path is nuget restore packages.config -PackagesDirectory ..\..\packages, which does not exist.
GoCD exec task requires you to explicitly separate process executable and all arguments. So the above nuget example would have to be configured like so:
<exec command="nuget" workingdir="EMApp\EMApp\EMApp.iOS">
<arg>restore</arg>
<arg>packages.config</arg>
<arg>-PackagesDirectory</arg>
<arg>..\..\packages</arg>
</exec>
More tips on task setup:
If nuget.exe is not in the PATH, you'll need to configure full file path e.g. command="C:\nuget\nuget.exe"
Here is a nice blog post on exec tasks
If you don't like setting up process and arguments separately like this, try script executor plugin which will start a shell.
Edit 1
On mac you would need to run nuget with mono. So the process executable is mono:
<exec command="mono" workingdir="EMApp\EMApp\EMApp.iOS">
<arg>/path/to/nuget</arg>
<arg>restore</arg>
<arg>packages.config</arg>
<arg>-PackagesDirectory</arg>
<arg>..\..\packages</arg>
</exec>

Ant replace task doesn't work

I have Powershell script. It has a first line:
$installation_folder = #aaa#
And have an Ant buildfile with this task:
<target name="prepare-install-script" description="Preparation of installation script">
<replace file="install.ps1" propertyfile="${template-properties}">
<replacefilter token="#aaa#" value="installation.dir"/>
</replace>
</target>
All files are initialized. Logs said:
[replace] Replacing in c:\Users\install.ps1: #aaa# --> sdfsdf
But in the file nothing changed.
What can it be?
You have to change the encoding. This will work:
<target name="prepare-install-script" description="Preparation of installation script">
<replace file="install.ps1" token="#aaa#" value="installation.dir" encoding="UTF-16"/>
The problem was that when you write script in PowerShell default Windows IDE it became somethings like "binary" file with some system information. That's why Ant can't do replacing.
Fixing by copy script to simply text editor and save as ps1.

NuGet - install.ps1 does not get called

I'm trying to create my first NuGet package. I don't know why my install.ps1 script does not get called. This is directory structure
--Package
|
- MyPackage.nuspec
- tools
|
- Install.ps1
- some_xml_file
I build package using this command line
nuget.exe pack MyPackage.nuspec
When I Install-Package from VS Package Manager Console install.ps1 does not get called.
I thought that maybe I had some errors in script and that's the reason so I commented out everything but
param($installPath, $toolsPath, $package, $project)
"ECHO"
But I don't see ECHO appearing in Package Manager Console. What can be wrong?
Install.ps will only be invoked if there is something in the \lib and/or \content folder, not for a "tools only" package, though. See here:
The package must have files in the content or lib folder for Install.ps1 to run. Just having something in the tools folder will not kick this off.
Use the Init.ps1 instead (however, this will be executed every time the solution is opened).
Install.ps1 (and Uninstall.ps1) are no longer called in v3, but you can use Init.ps1. See here:
Powershell script support was modified to no longer execute install
and uninstall scripts, but init scripts are still executed. Some of
the reasoning for this is the inability to determine which package
scripts need to be run when not all packages are directly referenced
by a project.
An alternative to the install script can sometimes be a package targets file. This targets file is automatically weaved into the project file (csproj, ...) and gets called with a build.
To allow Nuget to find this targets file and to weave it in, these two things are mandatory:
the name of the targets file must be <package-name>.targets
it must be saved in the folder build at the top level of the package
If you like to copy something to the output folder (e.g. some additional binaries, like native DLLs) you can put these binaries into the package under folder binaries and use this fragment in the targets file for the copying:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="CopyBinaries" BeforeTargets="BeforeBuild">
<CreateItem Include="$(MSBuildThisFileDirectory)..\binaries\**\*.*">
<Output TaskParameter="Include" ItemName="PackageBinaries" />
</CreateItem>
<Copy SourceFiles="#(PackageBinaries)"
DestinationFolder="$(OutputPath)\%(RecursiveDir)"
SkipUnchangedFiles="true"
OverwriteReadOnlyFiles="true"
/>
</Target>
</Project>

TeamCity and running NUnit tests

In TeamCity, i need to state exact locations of assemblies that contain NUnit tests to be executed.
Is there an option to state a .SLN file so it will look up these test projects dynamically?
You can use wildcard expressions in the Run tests from box:
Source\\**\bin\\**\*Tests.dll
The above would run tests from any assembly under any bin folder under the Source folder which contains 'Tests' at the end of the assembly name.
Depending on whether you're using MSBuild or NAnt, you can add an entry to your build script like this:
<ItemGroup>
<TestAssemblies Include="tests\\test*.dll"/>
<TestAssemblies Include="tests.lib\\test*.dll"/>
</ItemGroup>
<Target Name="runTests">
<Exec Command="$(teamcity_dotnet_nunitlauncher) v2.0 x86 NUnit-2.5.0 %(TestAssemblies)" />
</Target>
In the example above, the two TestAssemblies lines point to your assemblies.
You can read more about this here: http://blogs.jetbrains.com/teamcity/2008/09/24/using-teamcity-nunit-launcher/