How to include dacpac file from build in Solution Output Path [duplicate]
Asked Answered
G

1

5

Tools: Visual Studio 2015, SSDT

I have an Visual Studio SQL Project which works fine on it's own. I run my build and the dacpac file is in debug\bin\*.dacpac as expected.

The problem is this SQL project is part of a WinForms solution.

I have included the SQL project as a project reference in the Winforms Project.

It looks like visual studio only copies dlls from project reference bin folders into the output path bin\debug folder.

How can I configure Visual Studio to ALSO copy the dacpac file to the winform project's bin\debug folder (outputpath)?

With other files that are included in the project itself, this is easy. I can just edit the file properties to copy always to output path. For BIN output you cannot do that since the dacpac file is a build output, not part of the project itself.

Guthry answered 10/9, 2017 at 18:46 Comment(0)
N
6

How can I configure Visual Studio to ALSO copy the dacpac file to the winform project's bin\debug folder (outputpath)?

You can add a copy task in the Pre-build event of Winforms Project or in the Post-build event of SQL project.

Post-build event in SQL project:

xcopy /y "$(ProjectDir)$(OutDir)*.dacpac" "$(SolutionDir)YourWindowsFormsProjectName\$(OutDir)"

Pre-build event in Winform project:

xcopy /y "$(SolutionDir)YourSQLProjectName\$(OutDir)*.dacpac" "$(ProjectDir)$(OutDir)"

Here are some commonly used switches with xcopy:

/I - treat as a directory if copying multiple files
/Q - Do not display the files being copied.
/S - Copy subdirectories unless empty.
/E - Copy empty subdirectories.
/Y - Do not prompt for overwrite of existing files.
/R - Overwrite read only files.

Hope this help.

Nonprofit answered 11/9, 2017 at 6:2 Comment(3)
Man that is ugly! lol I will give it a try. I have no idea why Microsoft won't automatically copy the dacpac over. It DOES auto copy over the publish.xml file... so why not the dacpac? lolGuthry
I think it's because the dacpac is a build artifact - it only shows up when building. That means that you'll get different binaries based on whatever branch of code you're building. It shows up in its own project path, though you might be able to change the output w/ some work. I'm pretty sure that using the msbuild command line would give you a way to change the output as well, but realize that's not what you're seeking.Ferrari
@user5855178, just as Peter said: "It`s because the dacpac is a build artifact-it only shows up when building". So we could not change the properties "Copy to Output Director" of dacpac file to "Copy Always", this file would not copy to the output folder of reference project. Besides, build event can do this task very well, you can try it. #21668684Nonprofit

© 2022 - 2024 — McMap. All rights reserved.