Ant replace task doesn't work - powershell

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.

Related

Run a command in ccnet.config

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.

OpenCover Can't find file location

I'm trying run a build args against open cover but I can't find the file location since there are spaces in the location itself
<executable>C:\Program Files (x86)\OpenCover\OpenCover.Console.exe</executable>
<buildArgs>-register:user -target:"C:\Program Files (x86)\NUnit 2.6.2\bin\nunit-console.exe" -targetargs:"C:\Users\username\Documents\Visual Studio 2010\Projects\WebCrawlerMVC\WebCrawlerMVC.Tests\bin\Debug\WebCrawlerMVC.Tests.dll" /noshadow /xml=reports\TestResult.xml" - filter:"+[WebCrawlerMVC.Tests*]* -output:"C:\Program Files (x86)\CruiseControl.NET\server\reports\coverage.xml" </buildArgs>
</exec>
<exec>
<executable>C:\Program Files (x86)\ReportGenerator\bin\ReportGenerator.exe</executable>
<buildArgs>-reports:reports\coverage.xml</buildArgs>
the error comes out as File type not known: C:Users\username\Documents\Visual when i run it through the OpenCover console
so it's not being able to view the whole file path, is there a way around this? I realize my whole argument will have some errors still, but I can't get to fixing them until I resolve this one.
Update:
targetargs:"\"C:\Users\lardern\Documents\Visual Studio 2010\Projects\WebCrawlerMVC\WebCrawlerMVC.Tests\bin\Debug\WebCrawlerMVC.Tests.dll"
the "\ "C: seems to allow the spacing to go through, I still have errors with my code, but its no longer a file path issue.
Update2:
<task>
<exec>
<executable>C:\Program Files (x86)\OpenCover\OpenCover.Console.exe</executable>
<buildargs>-target:"C:\Program Files (x86)\NUnit 2.6.2\bin\nunit-console.exe" -register:user -targetargs:"/nologo /noshadow \"C:\Users\username\Documents\Visual Studio 2010\Projects\WebCrawlerMVC\WebCrawlerMVC.Tests\bin\Debug\WebCrawlerMVC.Tests.dll" -filter:+[WebCrawlerMVC]* -output:coverage.xml </buildargs>
</exec>
</tasks>
this is this is the working version.
try escaping the quotes wrapping the path to the assembly
<buildArgs>-register:user -target:"C:\Program Files (x86)\NUnit 2.6.2\bin\nunit-console.exe"
"-targetargs:\"C:\Users\username\Documents\Visual Studio 2010\Projects\WebCrawlerMVC\WebCrawlerMVC.Tests\bin\Debug\WebCrawlerMVC.Tests.dll\" /noshadow /xml=reports\TestResult.xml" - filter:"+[WebCrawlerMVC.Tests*]*" -output:"C:\Program Files (x86)\CruiseControl.NET\server\reports\coverage.xml" </buildArgs>
Maybe this link will provide a bit of help.
The environment variables are expanded before being passed to opencover and it looks like you have spaces in your path name. The Usage Wiki describes that arguments with spaces in them have to be escaped with \". I recommend you create a new variable with escaped paths for use with OpenCover.
Just a thought.

CodeAssassin.ConfigTransform for of arbitrarily named config files

NuGet packages such as CodeAssassin.ConfigTransform tranform web.*.config or app.*.config to web.*.config.transformed or app.*.config.transformed upon a VS build.
However, what if you have config files of form {arbitrary-name}.config ?
For example, MyAssembly.dll.config and its transform rulesets MyAssembly.dll.debug.config & MyAssembly.dll.release.config
CodeAssassin.ConfigTransform does not appear to work for these file patterns.
If you look at the target source code it looks quite simple to modify it to allow any .config file to be transformed. Actually I think that transforming any XML file should be possible.
I will fork that repository tomorrow for and experiment with this.
Disclaimer: In this example I modified CodeAssassin.ConfigTransform.targets directly. But you should create a separate .targets file and reference that in your .csproj.
Add a ConnectionString.config (as an example) and then add the transforms.
Add this to the .targets file (your config name just has to match the regex expression - (?i)^ConnectionString\. in this case):
<Target Name="TransformAllConnectionStringConfigTransformFiles"
Condition="'$(WebProjectOutputDir)'!=''"
BeforeTargets="Compile">
<ItemGroup>
<ConnectionStringConfigTransformFile Include="#(None);#(Content)" Condition="'$([System.Text.RegularExpressions.Regex]::IsMatch(%(Filename),"(?i)^ConnectionString\."))' == true and '%(Extension)'=='.config'" />
</ItemGroup>
<TransformXml Source="ConnectionString.config" Destination="%(ConnectionStringConfigTransformFile.Identity).transformed" Transform="#(ConnectionStringConfigTransformFile)"
Condition="'#(ConnectionStringConfigTransformFile)'!=''" />
<CreateItem Include="%(ConnectionStringConfigTransformFile.Identity).transformed"
AdditionalMetadata="CopyToOutputDirectory=Always">
<Output TaskParameter="Include" ItemName="Content"/>
</CreateItem>
</Target>
Build, and your .transformed files are created.

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/