Get code from TFS with nant - tfs

I want to take latest source from the Team Foundation Source control project directory to my local machine directory using NAnt build script.
for that i have used:-
<?xml version="1.0"?>
<project name="TFUse_GetFiles" default="GetTFSFiles">
<target name="GetTFSFiles" >
<exec program="C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\TF.exe">
<arg value="get" />
<arg value="/login:Domain name\loginid,password" />
<arg value="$/Projects/dir/Main" />
<arg value="/force" />
</exec>
</target>
</project>
the result is showing as [exec]All files are up to date , but no files are copied to my local folder..
So please help me about this probleam if any body has done above mentioned task before.
Thanks,

The TFS client will only download files that are out of date according to the TFS server: it knows previous what gets have taken place to the workspace.
You could use the /force option on tf get to get everything whatever the server has recorded.

It's like Richard says, in addition: if your $/Projects/dir/Main is not a valid source path, TF.exe again replies with "All files are up to date".
You can find the valid path by navigating within source control explorer to the target path & then checking the 'Source location' entry.

Adding /recursive as an argument solved my problem of NAnt returning "All files are up to date" even though there were in fact new and updated files to get.

Related

Process leaked file descriptors jenkins ERROR on Jenkins

Can someone help me to solve an issue "process leaked file descriptors jenkins"?
I tried whit BUIL_ID = dontkillme but it doesnt work.
Thx
It would help to know more about what you're trying to run but this question came up as a result of troubleshooting an issue I was having so here's how I resolved it. I am using Windows so if you're using something else it may not work for you.
First of all you need to read and understand the Jenkins documentation on the issue: https://jenkins.io/redirect/troubleshooting/process-leaked-file-descriptors
I had to install Ant first since it was not installed.
https://ant.apache.org/bindownload.cgi
The Jenkins documentation gives you an example Ant script:
<exec executable="cscript.exe">
<env key="ANTRUN_TITLE" value="Title for Window" /> <!-- optional -->
<env key="ANTRUN_OUTPUT" value="output.log" /> <!-- optional -->
<arg value="//NoLogo" />
<arg value="antRunAsync.js" /> <!-- this script -->
<arg value="real executable" />
</exec>
You will change the "real executable" to be the executable you are wanting to run.
See that .js file in the 2nd arg value? You will need to create that. There's a link to this on the Jenkins documentation page too. Grab it here: https://wiki.jenkins.io/download/attachments/1835010/antRunAsync.js?version=1&modificationDate=1184046328000&api=v2
I didn't make any edits to the contents, just pasted it right in and saved it as antRunAsync.js
So now you take your Ant example script I posted above and throw that in a text editor, save as build.xml
From this point you should be able to test on the command line by typing ant and pressing enter. Your application should load in a different window.
If you haven't set up Ant in the Jenkins Global Tool Configuration do so now and point it to your Ant install (might have to uncheck the Install checkbox). In the Jenkins project add a build step Invoke Ant. Set that up how you like according to Ant documentation.
Hope this answer helps someone else who has stumbled across this problem and this question.

Get full path of .sln file

How does one get the full physical path of the .sln file when scripting in MSBuild?
I'm trying to force nuget to download packages using:
<Target Name="BeforeCompileConfiguration">
<Exec Command=""$(ToolsHome)NuGet\NuGet.exe" restore "$(SolutionRoot)\KK\MyProject.sln"" />
</Target>
KK is the name of the folder that the .sln file is under. I'd like to replace
$(SolutionRoot)\KK\MyProject.sln
with a single $() build property.
$(SolutionPath)
should do your job!
By the way it's equivalent to:
$(SolutionDir)$(SolutionFileName)

TFS MSBuild copy command

The is my copy command:
<ItemGroup>
<SwfFiles Include="$(MSBuildProjectDirectory)\bin-release\**\*.*"/>
</ItemGroup>
<CallTarget Targets="CopyFilesToDropLocation"/>
<Target Name="CopyFilesToDropLocation">
<Copy
SourceFiles="#(SwfFiles)"
DestinationFiles="#(SwfFiles->'$(OutDir)_PublishedWebsites\PrismWeb\% (RecursiveDir)%(Filename)%(Extension)')"/>
</Target>
I dont anything being copied to the destinaton. Any idea what am I doing wrong?
IS this space for hiding values ?
DestinationFiles="#(SwfFiles->'$(OutDir)_PublishedWebsites\PrismWeb\% [here] (RecursiveDir)%(Filename)%(Extension)')"/>
I tested this with some of my code
<Copy SourceFiles="#(SourceAllFiles)" DestinationFiles="% (RecursiveDir)%(Filename)%(Extension)'" />
This space will produce a copy that works, but it tries to copy the source to this destination:
% [nbSpaces](RecursiveDir)[this part of the metadata woks]
You should use the latest build template in TFS 2013.4. It has defined locations for executing PowerShell, one of which is post-build. Using Powershell is both easyer to debug and more future proof.

MSbuild error while chekout : exited with code 9009

I am try to chekout my file from TFS using MSBuild script. But I am getting "exited with code 9009"
My code is bellow :
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build">
<PropertyGroup>
<TfCommand>
"C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\tf.exe"
</TfCommand>
</PropertyGroup>
<Target Name="Build">
<Exec Command="$(TfCommand) checkout "$/ApplicationSharedServices/release/dev_branch/renderer/bin/MIME.dll""/>
</Target>
</Project>
As per Just TFS's answer, you need to be in the folder that is in your workspace before you run TF. it might work fine with VS but with MSBuild pure you need to be in the folder. Now you technically don't need to put the full path when doing the get then. just MIME.dll.
Just out of curiosity, why are you running an MSBuild TF get command? is this in you automated build? You should start using PowerShell and run a pre-build script to get the info you need. You could also use Nuget with package restore to get any DLLs needed for compilation.
Cheers,
ET

Adding files to the bin directory at Build and Publish

I have two license files that I would like to include in my \bin directory both when I build and publish.
Both files are in the App_Data directory (their initial location doesn't matter, they just need to end up in the \bin) and have the following properties set:
Build Action = Content
Copy to Output Directory = Copy Always
They are in not the \bin when I build or publish.
What is wrong with my setup: the settings, the folders, the files, something else...?
UPDATE
I moved the files out of the App_Data directory and placed them in the project root and now they are copied to the \bin on build.
I've done this in a few projects by expanding my .csproject file slightly. The following code should be put directly beneath the Project node in your WebProject.csproj.
The AfterBuild target simply copies a set of files ("unreferenced DLLs" in this case) to the bin-folder when building normally from Visual Studio. The CustomCollectFiles basically do the same thing when deploying.
<PropertyGroup>
<UnreferencedDlls>..\lib\Unreferenced\**\*.dll</UnreferencedDlls>
</PropertyGroup>
<PropertyGroup>
<CopyAllFilesToSingleFolderForPackageDependsOn>
CustomCollectFiles;
$(CopyAllFilesToSingleFolderForPackageDependsOn);
</CopyAllFilesToSingleFolderForPackageDependsOn>
</PropertyGroup>
<Target Name="AfterBuild">
<Message Text="Copying unreferenced DLLs to bin" Importance="High" />
<CreateItem Include="$(UnreferencedDlls)">
<Output TaskParameter="Include" ItemName="_UnReferencedDLLs" />
</CreateItem>
<Copy SourceFiles="#(_UnReferencedDLLs)" DestinationFolder="bin\%(RecursiveDir)" SkipUnchangedFiles="true" />
</Target>
<Target Name="CustomCollectFiles">
<Message Text="Publishing unreferenced DLLs" Importance="High" />
<ItemGroup>
<_CustomFiles Include="$(UnreferencedDlls)" />
<FilesForPackagingFromProject Include="%(_CustomFiles.Identity)">
<DestinationRelativePath>bin\%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath>
</FilesForPackagingFromProject>
</ItemGroup>
</Target>
The part you need to modify is basically the UnreferencedDlls node to match your folder structure. The **\*.dll part simply means "every DLL file at any level beneath here".
If you're using Visual Studio:
Show your file properties (Click on your file or Right-click on it then choose Properties)
At the Copy to Output Directory property choose Copy always or Copy if newer.
At build time, the file is going to be copied at the bin directory: Debug or Release...
not necessarily a direct answer, but I highly suggest not using the baked in "publish" mechanism, but rather wire up a build script (probably in powershell) that will do everything you need. It's really easy to hook into MSBuild as well as nUnit and also copy files and move them around.
POWERSHELL (rough) example.
# Get Directory Location
$invocation = (Get-Variable MyInvocation).Value
$directorypath = Split-Path $invocation.MyCommand.Path
# Build the application using MSBuild
cmd /c C:\Windows\Microsoft.NET\Framework\$v4_net_version\msbuild.exe "$directorypath\MyProject.sln" /p:Configuration=Release
# Run the tests using nUnit
cmd /c $directorypath\build\nunit\nunit-console.exe $solutionPath\MyProject.Tests\bin\debug\MyProject.Tests.dll
# Copy the license to the appropriate directory
Copy-Item -LiteralPath "$directorypath\mylicensefile.txt" "$directorypath\bin\release" -Force
# NOTE: You are going to have to adjust this to match your solution and projects.
In this post on Microsoft Connect the answer is much simpler:
Referenced assemblies in Unit Test are not copied in TestResults/Out
So what I did was the following:
[TestClass]
[DeploymentItem("Some.dll")]
public class SomeTests
{
...
}
It works fine for me.
Hope it help.

Resources