1

Background

In Visual Studio 2013, targeting a TFS 2012 instance, I have 2 projects within my solution:

  1. a .sqlproj database project ("Project D"). This project outputs a .dll and a .dacpac file.
  2. a WPF project ("Project W") that holds a project reference to the database project.

The build output folder of Project W must contain the .dll and the .dacpac file from Project D--in addition to its own .exe. As expected, the project reference only causes the .dll from Project D to be copied to Project W's output folder. To get the .dacpac file as well, I include a linked file reference in Project W to the .dacpac file from Project D's output.

Problem

This works well in Visual Studio, but fails in TFS build, with the following error:

C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Microsoft.Common.targets (3686): Could not copy the file "d:\TfsBuilds\2\...\ProjectD\bin\debug\ProjectD.dacpac" because it was not found.

Things I've tried (unsuccessfully)

Similar questions, like this and this, have different causes, and don't help me resolve the issue.

Solutions that:

  1. control the folder structure of the binaries output folder, or
  2. combine all the output for the solution's build into a single folder

still fail, because in every case, Project D's build output--including the .dacpac file--is placed below the build agent's folder in the drop folder, while project W's linked file reference is expecting the .dacpac file to be in a folder beneath Project D's source files within the build agent's mapped workspace, relative to Project W (i.e., "..\ProjectD\bin\debug\ProjectD.dacpac".) (paragraph edited for accuracy.)

Question

How can I configure my solution/projects in this particular scenario, so that they work both in Visual Studio and TFS Build?

(In my mind, the ideal would be if there was some special sort of "project reference" that would grab all the output of a referenced project, instead of just the .dlls.)

Community
  • 1
  • 1
Richard II
  • 853
  • 9
  • 31
  • Why do you have a project referencing a dacpac? This is not something that teams typically would do. – Dylan Smith Mar 18 '14 at 16:10
  • @DylanSmith, the WPF project executes SqlPackage.exe in a .Net Process, and the .dacpac file is used in the /SourceFile: argument. If you have a suggestion for a better approach, I'm all ears. – Richard II Mar 18 '14 at 16:36
  • Maybe this can help you: http://social.msdn.microsoft.com/Forums/en-US/f5521503-7392-4da7-a092-8c13208e2570/can-output-dacpac-pathfilename-be-changed-from-tfs-build?forum=ssdt – Morten Frederiksen Mar 24 '14 at 17:23

2 Answers2

2

When you are packaging your WPF app just copy the dacpac into the package. If you just xcopy deploy, make sure to copy over the dacpac from the build outputs in addition to your WPF app. I usually have a powershell script I call from my TFSBuild that pulls together all the files I need into a package for deployment.

Dylan Smith
  • 22,069
  • 2
  • 47
  • 62
  • I did not actually implement this, because a few days after posting my question, my company upgraded to TFS 2013, so I was able to accomplish my goal in a simpler manner. I am marking this answer as accepted, because it pointed me in the right direction, and I was well on my way to a resolution in TFS 2012 using his suggestions. – Richard II Mar 25 '14 at 12:26
0

Have your build tasks that execute SqlPackage use the $(OutputPath) variable to locate the dacpac file. TfsBuild overrides this MSBuild variable to instruct projects where to place their outputs.

Dylan Smith
  • 22,069
  • 2
  • 47
  • 62
  • SqlPackage.exe is not invoked during the build. It's invoked at runtime, by the WPF application running at the client site, to create a database using the .dacpac file. That's why the .dacpac file needs to be included in the WPF application's build output – Richard II Mar 18 '14 at 16:44
  • 1
    In that case when you are packaging your WPF app just copy the dacpac into the package. If you just xcopy deploy, make sure to copy over the dacpac from the build outputs in addition to your WPF app. I usually have a powershell script I call from my TFSBuild that pulls together all the files I need into a package for deployment. – Dylan Smith Mar 18 '14 at 16:59
  • if you add the preceding comment as an answer, I will mark it as accepted. I can't mark the answer itself as accepted, for reasons stated in my first comment to it. – Richard II Mar 24 '14 at 14:01