MSBuild Message Output Twice - tfs

I have the following Target:
<Target Name="SetBinariesLocationForTeamBuild">
<!--We add the following location paths because TFS Team Build first copies to \sources and \binaries folders
rather than simply having the binaries in a \bin folder of the source folder
at this point the build will be at: C:\Builds\3\x.Int.MIS\SupportBTDF\Sources\x.Int.MIS\Dev\V1.0\Src\Solutions\MIS\x.Int.MIS.Deployment
so we need to go up 4 levels before going back down to binaries-->
<Message Text="Value of TeamBuild=$(TeamBuild)"/>
<Message Text="MSBuildProjectName: $(MSBuildProjectName)"/>
<Message Text="MSBuildStartupDirectory: $(MSBuildStartupDirectory)"/>
<Message Text="MSBuildProjectDirectory: $(MSBuildProjectDirectory)"/>
<Message Text="MSBuildProjectFullPath: $(MSBuildProjectFullPath)"/>
<Message Text="MSBuildThisFileDirectory: $(MSBuildThisFileDirectory)"/>
<ItemGroup>
<Schemas Condition ="'$(TeamBuild)' == 'True'" Include="x.Int.MIS.Schemas.dll">
<LocationPath>..\..\..\..\..\..\..\..\binaries\</LocationPath>
</Schemas>
</ItemGroup>
<ItemGroup>
<Pipelines Condition ="'$(TeamBuild)' == 'True'" Include="x.Int.Pipelines.dll">
<LocationPath>..\..\..\..\..\..\..\..\binaries\</LocationPath>
</Pipelines>
</ItemGroup>
<ItemGroup>
<PipelineComponents Condition ="'$(TeamBuild)' == 'True'" Include="x.Int.PipelineComponents.dll">
<LocationPath>..\..\..\..\..\..\..\..\binaries\</LocationPath>
</PipelineComponents>
</ItemGroup>
<ItemGroup>
<Orchestrations Condition ="'$(TeamBuild)' == 'True'" Include="x.Int.Orchestrations.dll">
<LocationPath>..\..\..\..\..\..\..\..\binaries\</LocationPath>
</Orchestrations>
</ItemGroup>
<ItemGroup>
<Transforms Condition ="'$(TeamBuild)' == 'True'" Include="x.Int.Transforms.dll">
<LocationPath>..\..\..\..\..\..\..\..\binaries\</LocationPath>
</Transforms>
</ItemGroup>
<Message Text="What is Schemas location path: %(Schemas.LocationPath)"/>
<Message Text="What is Pipelines location path: %(Pipelines.LocationPath)"/>
</Target>
I run the project from the command line passing in /p:TeamBuild=True /t:SetBinariesForTeamBuild. The output has me very puzzled...
Microsoft (R) Build Engine Version 4.0.30319.1
[Microsoft .NET Framework, Version 4.0.30319.269]
Copyright (C) Microsoft Corporation 2007. All rights reserved.
Build started 24/07/2012 16:59:08.
Project "C:\Builds\3\x.Int.MIS\SupportBTDF\Sources\x.Int.MIS\Dev\V1.0\Src\Solutions\MIS\x.Int.MIS.Deployment\x.Int.MIS.Deployment.btdfproj" on node 1 (SetBinariesLocationForTeamBuild target(s)).
SetBinariesLocationForTeamBuild:
Value of TeamBuild=True
MSBuildProjectName: x.Int.MIS.Deployment
MSBuildStartupDirectory: C:\Builds\3\x.Int.MIS\SupportBTDF\Sources\x.Int.MIS\Dev\V1.0\Src\Solutions\MIS\x.Int.MIS.Deployment
MSBuildProjectDirectory: C:\Builds\3\x.Int.MIS\SupportBTDF\Sources\x.Int.MIS\Dev\V1.0\Src\Solutions\MIS\x.Int.MIS.Deployment
MSBuildProjectFullPath: C:\Builds\3\x.Int.MIS\SupportBTDF\Sources\x.Int.MIS\Dev\V1.0\Src\Solutions\MIS\x.Int.MIS.Deployment\x.Int.MIS.Deployment.btdfproj
MSBuildThisFileDirectory: C:\Builds\3\x.Int.MIS\SupportBTDF\Sources\x.Int.MIS\Dev\V1.0\Src\Solutions\MIS\x.Int.MIS.Deployment\
What is Schemas location path: ..\x.Int.MIS.Schemas\bin\Debug
What is Schemas location path: ..\..\..\..\..\..\..\..\binaries\
What is Pipelines location path: ..\x.Int.MIS.Pipelines\bin\Debug
What is Pipelines location path: ..\..\..\..\..\..\..\..\binaries\
Done Building Project "C:\Builds\3\x.Int.MIS\SupportBTDF\Sources\x.Int.MIS\Dev\V1.0\Src\Solutions\MIS\x.Int.MIS.Deployment\x.Int.MIS.Deployment.btdfproj" (SetBinariesLocationForTeamBuild target(s)).
Build succeeded.
0 Warning(s)
0 Error(s)
Time Elapsed 00:00:00.17
I want the location path to be the one with 8 ..\ but it is not - any idea why and why it gets printed twice!?

The #(Schemas) and #(Pipelines) item arrays are each getting another item tuple added to them, or else they couldn't be printing out. There must be another target that is getting run in which this happens. If you are running msbuild on the project using the exact command line, then the additional target would have to be either an entry in an InitialTargets on a Project, or else a target wired into the target above with a BeforeTargets or AfterTargets reference to this one.

Related

How do I specify a target architecture when building projects in Visual Studio code?

I am new to VS code/F# and I am trying to build a F# console app (on both Windows workstation and on my Linux computer).
I installed the Ionide extension together with FAKE.
The code I am considering is the Iris example (see How to translate the intro ML.Net demo to F#?), creating a New F# Project with Ionide and using Microsoft.ML.
My iris.fsproj is
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net461</TargetFramework>
<DebugType>portable</DebugType>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<ItemGroup>
<Compile Include="iris.fs" />
<None Include="App.config" />
</ItemGroup>
<Import Project="..\.paket\Paket.Restore.targets" />
</Project>
When running the script (which I do with the "play" button aka F#: run script provided with VS Code/Ionide) I get:
C:\Users\MyUser\.nuget\packages\microsoft.ml\0.2.0\build\Microsoft.ML.targets(16,5): error : Microsoft.ML currently supports 'x64' processor architectures. Please ensure your application is targeting 'x64'.
together with
Running build failed.
Error:
System.Exception: dotnet build failed
How do I target x64 with the project structure provided by Ionide?
It should be as simple as adding the following line to your PropertyGroup section:
<PlatformTarget>x64</PlatformTarget>
There are more complicated setups possible using the Condition attribute to set the platform target based on various command-line arguments to the compiler, but that should be the simplest way to get you up and running.

MSBuild giving "invalid version file" on F#

I'm recently unable to build F# with MSBuild. It is giving me an error "invalid version file". The generated compiler options below show --versionfile:version.htm being added, and I'm not sure why.
I did find that if I go to C:\Program Files (x86)\Microsoft SDKs\F#\4.0\Framework\v4.0\Microsoft.FSharp.targets, and remove the line VersionFile="$(VersionFile)" it starts working again. However I don't know where that file came from or why that line is there, and I don't want to be working with a non-standard dev box. Can anyone shed light on what's happening here?
Here's a dump of the whole output.
$ "C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe" "C:\Users\dafohl\Documents\Visual Studio 2015\Projects\Library1\Library1\Library1.fsproj"
Microsoft (R) Build Engine version 14.0.25420.1
Copyright (C) Microsoft Corporation. All rights reserved.
Build started 5/4/2017 6:10:21 PM.
Project "C:\Users\dafohl\Documents\Visual Studio 2015\Projects\Library1\Library1\Library1.fsproj" on node 1 (default targets).
CoreCompile:
C:\Program Files (x86)\Microsoft SDKs\F#\4.0\Framework\v4.0\fsc.exe -o:obj\Debug\Library1.dll -g --debug:full --noframework --define:DEBUG --define
:TRACE --doc:bin\Debug\Library1.XML --optimize- --tailcalls- --versionfile:version.htm -r:"C:\Program Files (x86)\Reference Assemblies\Microsoft\FS
harp\.NETFramework\v4.0\4.4.0.0\FSharp.Core.dll" -r:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6\mscorlib.dl
l" -r:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6\System.Core.dll" -r:"C:\Program Files (x86)\Reference Ass
emblies\Microsoft\Framework\.NETFramework\v4.6\System.dll" -r:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6\S
ystem.Numerics.dll" --target:library --warn:3 --warnaserror:76 --fullpaths --flaterrors --subsystemversion:6.00 --highentropyva+ "C:\Users\dafohl\A
ppData\Local\Temp\.NETFramework,Version=v4.6.AssemblyAttributes.fs" AssemblyInfo.fs Library1.fs
FSC : warning FS0075: The command-line option 'versionfile' is for test purposes only [C:\Users\dafohl\Documents\Visual Studio 2015\Projects\Library1 \Library1\Library1.fsproj]
FSC : warning FS2015: The 'AssemblyVersionAttribute' has been ignored because a version was given using a command line option [C:\Users\dafohl\Docume nts\Visual Studio 2015\Projects\Library1\Library1\Library1.fsproj]
FSC : error FS0205: Invalid version file 'C:\Users\dafohl\Documents\Visual Studio 2015\Projects\Library1\Library1\version.htm' [C:\Users\dafohl\Docum ents\Visual Studio 2015\Projects\Library1\Library1\Library1.fsproj]
Done Building Project "C:\Users\dafohl\Documents\Visual Studio 2015\Projects\Library1\Library1\Library1.fsproj" (default targets) -- FAILED.
Build FAILED.
"C:\Users\dafohl\Documents\Visual Studio 2015\Projects\Library1\Library1\Library1.fsproj" (default target) (1) ->
(CoreCompile target) ->
FSC : warning FS0075: The command-line option 'versionfile' is for test purposes only [C:\Users\dafohl\Documents\Visual Studio 2015\Projects\Librar y1\Library1\Library1.fsproj]
FSC : warning FS2015: The 'AssemblyVersionAttribute' has been ignored because a version was given using a command line option [C:\Users\dafohl\Docu ments\Visual Studio 2015\Projects\Library1\Library1\Library1.fsproj]
"C:\Users\dafohl\Documents\Visual Studio 2015\Projects\Library1\Library1\Library1.fsproj" (default target) (1) ->
(CoreCompile target) ->
FSC : error FS0205: Invalid version file 'C:\Users\dafohl\Documents\Visual Studio 2015\Projects\Library1\Library1\version.htm' [C:\Users\dafohl\Doc uments\Visual Studio 2015\Projects\Library1\Library1\Library1.fsproj]
2 Warning(s)
1 Error(s)
Time Elapsed 00:00:00.68
Here are the original contents of Microsoft.FSharp.targets:
WARNING: DO NOT MODIFY this file unless you are knowledgeable about MSBuild and have
created a backup copy. Incorrect changes to this file will make it
impossible to load or build your projects from the command-line or the IDE.
This file defines the steps in the standard build process specific for F# .NET projects.
For example, it contains the step that actually calls the F# compiler. The remainder
of the build process is defined in Microsoft.Common.targets, which is imported by
this file.
Copyright (C) Microsoft Corporation. All rights reserved.
***********************************************************************************************
-->
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<UsingTask TaskName="Fsc" AssemblyFile="FSharp.Build.dll"/>
<UsingTask TaskName="CreateFSharpManifestResourceName" AssemblyFile="FSharp.Build.dll"/>
<PropertyGroup>
<ImportByWildcardBeforeMicrosoftFSharpTargets Condition="'$(ImportByWildcardBeforeMicrosoftFSharpTargets)' == ''">true</ImportByWildcardBeforeMicrosoftFSharpTargets>
<ImportByWildcardAfterMicrosoftFSharpTargets Condition="'$(ImportByWildcardAfterMicrosoftFSharpTargets)' == ''">true</ImportByWildcardAfterMicrosoftFSharpTargets>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\$(MSBuildThisFile)\ImportBefore\*" Condition="'$(ImportByWildcardBeforeMicrosoftFSharpTargets)' == 'true' and exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\$(MSBuildThisFile)\ImportBefore')"/>
<PropertyGroup>
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
<DefaultLanguageSourceExtension>.fs</DefaultLanguageSourceExtension>
<Language>F#</Language>
<TargetRuntime>Managed</TargetRuntime>
<Tailcalls Condition="'$(Tailcalls)'==''">$(Optimize)</Tailcalls>
<FrameworkRegistryBase Condition="'$(TargetFrameworkIdentifier)'=='Silverlight'">Software\Microsoft\Microsoft SDKs\$(TargetFrameworkIdentifier)</FrameworkRegistryBase>
<!-- Visual studio requires a non-empty RootNamespace value for "Add New Item" to work. -->
<RootNamespace Condition="'$(RootNamespace)'==''">RootNamespace</RootNamespace>
<Actual32Bit Condition="'$(TargetFrameworkVersion)'=='v2.0' or '$(TargetFrameworkVersion)'=='v3.0' or '$(TargetFrameworkVersion)'=='v3.5' or '$(TargetFrameworkVersion)'=='v4.0'">false</Actual32Bit>
<Actual32Bit Condition="!('$(TargetFrameworkVersion)'=='v2.0' or '$(TargetFrameworkVersion)'=='v3.0' or '$(TargetFrameworkVersion)'=='v3.5' or '$(TargetFrameworkVersion)'=='v4.0')">$(Prefer32Bit)</Actual32Bit>
</PropertyGroup>
<!--
The CreateManifestResourceNames target create the manifest resource names from the .RESX
files.
[IN]
#(EmbeddedResource) - The list of EmbeddedResource items that have been pre-processed to add metadata about resource type
Expected Metadata "Type" can either be "Resx" or "Non-Resx"
[OUT]
#(EmbeddedResource) - EmbeddedResource items with metadata
For F# applications the transformation is like:
Resources1.resx => Resources1 => Build into main assembly
SubFolder\Resources1.resx => SubFolder.Resources1 => Build into main assembly
Resources1.fr.resx => Resources1.fr => Build into satellite assembly
Resources1.notaculture.resx => Resources1.notaculture => Build into main assembly
For other project systems, this transformation may be different.
-->
<PropertyGroup>
<CreateManifestResourceNamesDependsOn></CreateManifestResourceNamesDependsOn>
</PropertyGroup>
<Target
Name="CreateManifestResourceNames"
Condition="'#(EmbeddedResource)' != ''"
DependsOnTargets="$(CreateManifestResourceNamesDependsOn)"
>
<ItemGroup>
<_Temporary Remove="#(_Temporary)" />
</ItemGroup>
<!-- Create manifest names for culture and non-culture Resx files, and for non-culture Non-Resx resources -->
<CreateFSharpManifestResourceName
ResourceFiles="#(EmbeddedResource)"
RootNamespace="$(RootNamespace)"
Condition="'%(EmbeddedResource.ManifestResourceName)' == '' and ('%(EmbeddedResource.WithCulture)' == 'false' or '%(EmbeddedResource.Type)' == 'Resx')">
<Output TaskParameter="ResourceFilesWithManifestResourceNames" ItemName="_Temporary" />
</CreateFSharpManifestResourceName>
<!-- Create manifest names for all culture non-resx resources -->
<CreateFSharpManifestResourceName
ResourceFiles="#(EmbeddedResource)"
RootNamespace="$(RootNamespace)"
PrependCultureAsDirectory="false"
Condition="'%(EmbeddedResource.ManifestResourceName)' == '' and '%(EmbeddedResource.WithCulture)' == 'true' and '%(EmbeddedResource.Type)' == 'Non-Resx'">
<Output TaskParameter="ResourceFilesWithManifestResourceNames" ItemName="_Temporary" />
</CreateFSharpManifestResourceName>
<ItemGroup>
<EmbeddedResource Remove="#(EmbeddedResource)" Condition="'%(EmbeddedResource.ManifestResourceName)' == ''"/>
<EmbeddedResource Include="#(_Temporary)" />
<_Temporary Remove="#(_Temporary)" />
</ItemGroup>
</Target>
<ItemGroup>
<DocFileItem Include="$(DocumentationFile)" Condition="'$(DocumentationFile)'!=''"/>
</ItemGroup>
<ItemGroup Condition="'$(_DebugSymbolsProduced)' == 'true' and '$(PdbFile)' != ''">
<_DebugSymbolsIntermediatePathTemporary Include="$(PdbFile)"/>
<!-- Add any missing .pdb extension, as the compiler does -->
<_DebugSymbolsIntermediatePath Include="#(_DebugSymbolsIntermediatePathTemporary->'%(RootDir)%(Directory)%(Filename).pdb')"/>
</ItemGroup>
<PropertyGroup>
<CoreCompileDependsOn>_ComputeNonExistentFileProperty</CoreCompileDependsOn>
</PropertyGroup>
<Target
Name="CoreCompile"
Inputs="$(MSBuildAllProjects);
#(CompileBefore);
#(Compile);
#(CompileAfter);
#(_CoreCompileResourceInputs);
$(ApplicationIcon);
$(AssemblyOriginatorKeyFile);
#(ReferencePath);
#(CompiledLicenseFile);
#(EmbeddedDocumentation);
$(Win32Resource);
$(Win32Manifest);
#(CustomAdditionalCompileInputs);
$(VersionFile);
$(KeyOriginatorFile)"
Outputs="#(DocFileItem);
#(IntermediateAssembly);
#(_DebugSymbolsIntermediatePath);
$(NonExistentFile);
#(CustomAdditionalCompileOutputs)"
Returns=""
DependsOnTargets="$(CoreCompileDependsOn)"
>
<Error
Condition="'$(SilverlightVersion)' != '' and '$(SilverlightVersion)' != 'v5.0'"
Text="In this version of Visual Studio, F# for Silverlight can only target Silverlight v5.0. Use a prior version of Visual Studio to target previous versions of Silverlight with F#."
/>
<Warning
Condition="'$(Win32ResourceFile)' != '' "
Text="The property <Win32ResourceFile> has been renamed to <Win32Resource>. Update your project file to ensure that the correct value is passed via the --win32res option to the F# compiler."
/>
<!-- Condition is to filter out the _CoreCompileResourceInputs so that it doesn't pass in culture resources to the compiler -->
<Fsc Condition=" '%(_CoreCompileResourceInputs.WithCulture)' != 'true' "
BaseAddress="$(BaseAddress)"
CodePage="$(CodePage)"
DebugSymbols="$(DebugSymbols)"
DebugType="$(DebugType)"
DefineConstants="$(DefineConstants)"
DisabledWarnings="$(NoWarn)"
DocumentationFile="$(DocumentationFile)"
GenerateInterfaceFile="$(GenerateInterfaceFile)"
KeyFile="$(KeyOriginatorFile)"
LCID="$(LCID)"
NoFramework="true"
Optimize="$(Optimize)"
OtherFlags="$(OtherFlags)"
OutputAssembly="#(IntermediateAssembly)"
PdbFile="$(PdbFile)"
Platform="$(PlatformTarget)"
Prefer32Bit="$(Actual32Bit)"
References="#(ReferencePath)"
ReferencePath="$(ReferencePath)"
Resources="#(_CoreCompileResourceInputs);#(CompiledLicenseFile);#(AdditionalEmbeddedResource)"
Sources="#(CompileBefore);#(Compile);#(CompileAfter)"
Tailcalls="$(Tailcalls)"
TargetType="$(OutputType)"
ToolExe="$(FscToolExe)"
ToolPath="$(FscToolPath)"
TreatWarningsAsErrors="$(TreatWarningsAsErrors)"
Utf8Output="$(Utf8Output)"
VersionFile="$(VersionFile)"
VisualStudioStyleErrors="$(VisualStudioStyleErrors)"
WarningLevel="$(WarningLevel)"
WarningsAsErrors="$(WarningsAsErrors)"
Win32ManifestFile="$(Win32Manifest)"
Win32ResourceFile="$(Win32Resource)"
SubsystemVersion="$(SubsystemVersion)"
HighEntropyVA="$(HighEntropyVA)"
TargetProfile="$(TargetProfile)"
SqmSessionGuid="$(SqmSessionGuid)"
/>
<ItemGroup>
<_CoreCompileResourceInputs Remove="#(_CoreCompileResourceInputs)" />
</ItemGroup>
</Target>
<Import Project="$(MSBuildBinPath)\Microsoft.Common.targets"/>
<!--
============================================================
GenerateTargetFrameworkMonikerAttribute
Emit the target framework moniker attribute as a code fragment into a temporary source file for the compiler.
============================================================
-->
<Target Name="GenerateTargetFrameworkMonikerAttribute" BeforeTargets="BeforeCompile" DependsOnTargets="PrepareForBuild;GetReferenceAssemblyPaths" Inputs="$(MSBuildThisFileFullPath)" Outputs="$(TargetFrameworkMonikerAssemblyAttributesPath)" Condition="'$(GenerateTargetFrameworkAttribute)' == 'true'">
<PropertyGroup>
<!-- This attribute is only available in mscorlib v4 and later -->
<AdditionalSourcesText Condition="'$(TargetFrameworkMoniker)' != '' and '$(TargetingClr2Framework)' != 'true'">
$(AdditionalSourcesText)
namespace Microsoft.BuildSettings
[<System.Runtime.Versioning.TargetFrameworkAttribute("$(TargetFrameworkMoniker)", FrameworkDisplayName="$(TargetFrameworkMonikerDisplayName)")>]
do ()
</AdditionalSourcesText>
</PropertyGroup>
<!-- This is a file shared between projects so we have to take care to handle simultaneous writes (by ContinueOnError)
and a race between clean from one project and build from another (by not adding to FilesWritten so it doesn't clean) -->
<WriteLinesToFile
File="$(TargetFrameworkMonikerAssemblyAttributesPath)"
Lines="$(AdditionalSourcesText)"
Condition="'$(AdditionalSourcesText)' != ''"
ContinueOnError="true"
Overwrite="true"/>
<ItemGroup>
<CompileBefore Include="$(TargetFrameworkMonikerAssemblyAttributesPath)" Condition="'$(AdditionalSourcesText)' != ''"/>
</ItemGroup>
</Target>
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\$(MSBuildThisFile)\ImportAfter\*" Condition="'$(ImportByWildcardAfterMicrosoftFSharpTargets)' == 'true' and exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\$(MSBuildThisFile)\ImportAfter')"/>
</Project>
Silly me, this was caused by some CoreXT setting in my work environment when launching VS from the command line where CoreXT had been loaded. When starting VS from a fresh command line or from the start menu the problem goes away.
No idea what setting exactly got changed by CoreXT or where, but that was definitely the culprit.

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.

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.

CustomizableOutDir=true breaks MSTest.exe during Team Build

When using CustomizableOutDir, I'm having problems with TFS Team Build firing off MSTest.exe properly.
TFSBuild.rsp
/verbosity:diagnostic
/p:CustomizableOutDir=true
TFSBuild.proj (solutions to build snippet)
<!-- code -->
<SolutionToBuild Include="$(BuildProjectFolderPath)/../../foo.csproj">
<Properties>OutputPath=$(BinariesRoot)\WindowsServices\foo\</Properties>
</SolutionToBuild>
<!-- tests -->
<SolutionToBuild Include="$(BuildProjectFolderPath)/../../test/test.sln">
<Targets>t1;t2</Targets>
<Properties>OutputPath=$(BinariesRoot)\TestHarness\</Properties>
</SolutionToBuild>
With both <Properties>OutputPath=$(BinariesRoot)\TestHarness\</Properties> and <Properties></Properties>, I get the following error at the end of the build:
"C:\build\BuildType\TFSBuild.proj"
(TestConfiguration target) (1:12) ->
(CoreTestConfiguration target) ->
MSBUILD : warning MSB6003: The
specified task executable "MSTest.exe"
could not be run. The directory name
is invalid
After finding this article, I and then added the following:
<Target Name="AfterCompile">
<ItemGroup>
<SolutionOutputs Condition="'%(CompilationOutputs.Solution)' == '$(Solution)'" Include="%(RootDir)%(Directory)**\*.*" />
<ServiceOutputs Include="$(BinariesRoot)\WindowsServices\**\*.*" />
<TestHarnessOutputs Include="$(BinariesRoot)\TestHarness\*.*" />
</ItemGroup>
<Copy SourceFiles="#(SolutionOutputs)" DestinationFolder="$(TeamBuildOutDir)" />
<Copy SourceFiles="#(ServiceOutputs)" DestinationFolder="$(TeamBuildOutDir)" />
<Copy SourceFiles="#(TestHarnessOutputs)" DestinationFolder="$(TeamBuildOutDir)" />
</Target>
Which gave this:
(AfterCompile target) ->
C:\build\BuildType\TFSBuild.proj(289,5):
error MSB3023: No destination
specified for Copy. Please supply
either "DestinationFiles" or
"DestinationDirectory".
DestinationDirectory is not part of the schema http://schemas.microsoft.com/developer/msbuild/2003, but I figured I would try it anyway. So I changed all the DestinationFolder on the copy tasks to DestinationDirectory and as expected I got this:
(AfterCompile target) ->
C:\build\BuildType\TFSBuild.proj(288,44):
error MSB4064: The
"DestinationDirectory" parameter is
not supported by the "Copy" task.
Verify the parameter exists on the
task, and it is a settable public
instance property.
C:\build\BuildType\TFSBuild.proj(288,5):
error MSB4063: The "Copy" task could
not be initialized with its input
parameters.
Anybody out there have CustomizableOutDir and MSTest working together in harmony with their TFS Team Build?
EDIT:
I found this discussion and applied this change:
<Target Name="BeforeTest">
<!-- The tests won't run if the binaries directory does not exist -->
<MakeDir
Directories="$(BinariesRoot)\%(ConfigurationToBuild.FlavorToBuild)"
Condition="!Exists('$(BinariesRoot)\%(ConfigurationToBuild.FlavorToBuild)')" />
</Target>
Which resulted in this:
"C:\build\BuildType\TFSBuild.proj"
(RunTest target) (1:11) ->
"C:\build\BuildType\TFSBuild.proj"
(TestConfiguration target) (1:12) ->
(CoreTestConfiguration target) ->
MSBUILD : warning MSB6006:
"MSTest.exe" exited with code 1.
This made tfs/mstest/msbuild happy.
<Target Name="BeforeTest">
<!-- The tests won't run if the binaries directory does not exist -->
<MakeDir
Directories="$(BinariesRoot)\%(ConfigurationToBuild.FlavorToBuild)"
Condition="!Exists('$(BinariesRoot)\%(ConfigurationToBuild.FlavorToBuild)')" />
</Target>
Not getting any test results was a different problem with the deployment and test box configuration.

Resources