tfs 2017 build multiple solutions dependency - tfs

How to create build definition for multiple solutions that have dependency?
Background here:
There are two solutions
Solution A is class library contains an object class 'ClassA'
Solution B is console program that use 'ClassA' by add dll reference generated by solution A.
I would like to server build both solutions using one TFS 2017 build definition.
It raise out error:
Main\Source\SolutionB\Program.cs (13, 13)
Main\Source\SolutionB\SolutionB\Program.cs(13,13): Error CS0246:
The type or namespace name 'SolutionA' could not be found (are you
missing a using directive or an assembly reference?)
How to config the build definition that SolutionB would know to use the dll generated from the build of SolutionA?

You should build your first project that will be used at second project as dll and than copy files to build artifacts; than publish your dlls to specific folder that you referenced in your second project and finally build your second project.
You can check this image that with similiar process, just in below image it is publishing artifacts to three diffrent location, in your case it should be one publish task.
This is one of the simple way; but if you use the project A for some other projects too you may want to use NuGet packages. I am going to describe this as solution 2.
Solution 2: You should create a Nuget packages by the artifacts of Project A. You can host your Nuget packages in custom source folder. Add your first project's package to your project as a reference. You don't need to do something extra just add a nuget restore task to your build definition. If you want, you can publish your first project as a nuget package during the build definiton. Please check how to restore and install neuget packages by build definiton.

Related

Nuget Packager the default XML namespace of the project must be the MSBuild XML namespace in TFS 2017

I changed the project type I am packaging from .net framework v4.6 to .net standard 2.0, now the build definition is failing in Nuget packager step and I am getting this error message.
[error]The default XML namespace of the project must be the MSBuild
XML namespace. If the project is authored in the MSBuild 2003 format,
please add xmlns="http://schemas.microsoft.com/developer/msbuild/2003"
to the element. If the project has been authored in the old
1.0 or 1.2 format, please convert it to MSBuild 2003 format.
After researching about this error I understand that the NuGet packer step doesn't work on SDK-based csproj formats.
What is the best alternative available? I found the same issue here, but I can not find the command pack within the available commands.
While the pack command does not appear in the dropdown, you can enter it manually into the field.
This is how I resolved this issue:
1- Add package metadata to .csproj file.
2- Go to project properties -> package and check "Generate NuGet package on build".
3- In Build definition add the following tasks:
a- NuGet Restore:
Set path to solution.
Select Feeds in my NuGet.config as Feeds to use.
Set path to Nuget.config (Usually project root "src\nuget.config").
b- Visual Studio Build:
Set path to solution.
Platform: something like $(BuildPlatform).
Configuration: something like $(BuildConfiguration).
c- Copy and Publish Build Artifacts:
In contents enter *.nupkg.
Set Copy Root, Artifact name, and Artifact type.

MSBuild builds solution but fails to build the project

I have F# project which I want to build with command line (to use that later in FAKE config).
The problem is that MSBuild fails to resolve assembly dependencies when I use it on the project file directly. While it goes fine when I use solution file with this single project included.
I really have run out of ideas. The solution file seems to not contain any critical information.
Another weird thing is that VSCode also fails to resolve one of those assemblies. I hope that when I fix MSBuild config I may be will able to see what's wrong with VSCode.
Command line:
"C:\Program Files (x86)\MSBuild\14.0\Bin\msbuild.exe" FSharpWeb1\FSharpWeb1.fsproj /t:rebuild
Error message:
C:\work\MNP\testMSBuild1\FSharpWebApi\FSharpWeb1\FSharpWeb1.fsproj(173,5): error MSB4062: The "MSBuild.ExtensionPack.FileSystem.File" task could not be loaded from the assembly C:\work\MNP\testMSBuild1\FSharpWebApi\FSharpWeb1\*Undefined*\packages\MSBuild.Extension.Pack.1.3.0\tools\net40\MSBuild.ExtensionPack.dll. Could not load file or assembly 'file:///C:\work\MNP\testMSBuild1\FSharpWebApi\FSharpWeb1\*Undefined*\packages\MSBuild.Extension.Pack.1.3.0\tools\net40\MSBuild.ExtensionPack.dll' or one of its dependencies. The filename, directory name, or volume label syntax is incorrect. Confirm that the <UsingTask> declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask.Done Building Project "C:\work\MNP\testMSBuild1\FSharpWebApi\FSharpWeb1\FSharpWeb1.fsproj" (rebuild target(s)) -- FAILED.
I've pushed the minimal demo to github: https://github.com/alehro/testMSBuild.git
It's actually easy to reproduce independently. In VS 2015 Community edition create new project from F# Web Template named "Web Api 2.2" and then try to build it with MSBuild.
Another disturbing thing is that the minimal demo produces different errors from those I've seen yesterday. Also vscode complains on different items. If yesterday it could not resolve a couple of calls, now it complains on all of:
open System.Net.Http
open System.Web
open System.Web.Http
open System.Web.Routing
telling that neither of them is defined.
Reformatting my comments to a response now that it's verified it works:
Your FSharpWeb1.fsproj references MSBuild.ExtensionPack.FileSystem.File task from MSBuild.Extension.Pack, but the path specified in the <UsingTask> tag contains $(SolutionDir) property which is not defined when you run MSBuild outside of Visual Studio.
The error message you're getting shows that in the highlighted part of the path:
The "MSBuild.ExtensionPack.FileSystem.File" task could not be loaded from the assembly C:\work\MNP\testMSBuild1\FSharpWebApi\FSharpWeb1\*Undefined*\packages\MSBuild.Extension.Pack.1.3.0\tools\net40\MSBuild.ExtensionPack.dll.
This can be remedied by conditionally setting the relative path when the property is not set by VS:
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
(original response for this solution: https://stackoverflow.com/a/33782131/1659828)
One more thing I mentioned in the comments is that this solution assumes you already have the necessary dependencies downloaded in the packages folder. Visual Studio does that automatically by restoring NuGet packages before build, but when you build in another context, you have to make sure the packages are restored, otherwise the build will keep failing.

How can I use project macros in TFS 2015 vNext Build definination?

I want to use macros of current csproj such as ${TargetPath} $(TargetName),in vNext Build defination as part of vs build task property of MSBuild argument,to do some copy etc.
But I found it not work,in build log, the macros did not be change into the absolute path.
Is there any way to use these macros just like in csproj post-build event?I did not find description about this on msdn ,and I could not use it in each csproj,because we have more than one thousand project files, edit the prj file one by one is not good:(
Thanks alot for your help.
Update
I want each project only output its own assembly without any referenced assembly when build.But I can't change project file to modify the reference property "copy local" to false.
You just need to add it as MSBuild arguments:
If you mean you want to achieve the function in post-build event same as this question Visual Studio Post Build Event - Copy to Relative Directory Location. There is no such thing like post-build in vnext build.
You can add several steps to copy the assemblies (One step for one project) and specify the copy root in the step.Refer to this question Copy one file in target directory on deploy from visual studio team services
However, as you have mentioned there are thousand project files. You can create a powershell script and add it in the build definition to copy the files.

Building project group from command line doesn't resolve project dependencies

I'm trying to build projects in project group from command line using MSBuild. After reading this page, my batch file looks like this:
SET BDS=C:\Program Files (x86)\Embarcadero\Studio\17.0
SET FrameworkDir=C:\Windows\Microsoft.NET\Framework
SET FrameworkVersion=v3.5
"%ProgramFiles(x86)%\MSBuild\14.0\Bin\MSBuild" .\Source\MyProjectGroup.groupproj /t:build /p:config=Debug /p:Platform=Win32 /verbosity:minimal /fileLogger /fileLoggerParameters:LogFile=Build.log;Verbosity=detailed;Append=true
Build fails, if I try to perform a "clean" build (that is, get source files from source control and run build from command line).
Looks like it tries to build projects in order they are placed in groupproj file. Consider this example:
there are two package projects, package A and package B;
package B requires package A;
package B is placed before package A in groupproj file.
In this case, "clean" build will fail, but if I reorder projects in project group, or build package A first, build will be successful.
E.g., MSBuild targets for C# resolve dependencies from project references.
But groupproj neither include dependencies info:
<Projects Include="NativePackages\Drawers\Drawers.dproj">
<Dependencies/>
</Projects>
nor processing DCC_Reference properties in dproj files:
<DCCReference Include="Drawers.dcp"/>
Am I doing something wrong?
Is there any option/property to trigger?
Could MSBuild targets for Delphi resolve dependencies automatically?
UPDATE
I know about "Dependencies..." context menu item in Project Manager (it just affects Dependencies tag in groupproj file).

Error While Creating Build

I have TFS 2010 and for one of the team project I have created the build definition (used default build template) and added the solution of one of the project. But when try to create build getting the following error:
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Microsoft.Common.targets
(902): The command "if Debug == Debug copy
"C:\Builds\14\\\Sources\ServerObjects..\SharedInterfaces\bin\debug*.dll"
"C:\Builds\14\\\Sources\ServerObjects..\ServerObjects\bin\debug"" exited with
code 1.
I think you maybe has wrong folder structure on the source control, see my answer on similar question here
teambuilding and deploying a dll (e.g. wpftoolkit.extended.dll)
TeamBuild overrides the output folder so the bin\debug (or bin\release) folder won't exist. It collates the output into Binaries.
For your custom build step use the obj folder instead of bin as that'll be the same under both TeamBuild and the local machine build.

Resources