How to include created database project created dacpac into a cs project

时光总嘲笑我的痴心妄想 提交于 2019-12-07 11:19:01

问题


I have a separate database project that I’d like to build within the same solution and then reference the created dacpac. When I try adding the database project it builds fine and the dll is added to the secondary project file, but the dacpac is not.

Is there a way that I can have the dacpac copied into my main project through the msbuild? I keep on thinking that there should be a way to modify either the sqlproj file or csproj file so that the dacpac is included as one of the project outputs. My knowledge of msbuild is not extensive, I’ve not been able to figure it out.

It seems to me that I need to add the dacpac somehow to say the '@(ReferenceCopyLocalPaths)' item but I have not been able to figure it out. Any tips or suggestions would be appreciated.

I tried doing something a little like what is referenced here MSBuild - ItemGroup of all bin directories within subdirectories by doing:

   <Target Name="AfterBuild">
    <Message Text="@(MainAssembly)" />
    <!--<DacPacs Include="%(ProjectReference.Directory)**"  />-->
    <ItemGroup>
      <DacPacs Include="%(ProjectReference.Directory)**/*bin*/*.dac" />
    </ItemGroup>
    <Message Text="@(ReferenceCopyLocalPaths)" />
    <Message Text="DacPacs: @(DacPacs)" />
    <Message Text="Target Database: $(TargetDatabase)" />
  </Target>

which gives nothing for DacPacs (when the wildcard is added). Also I tried referencing one of the item groups from the sqlproj file but it comes out empty to:


回答1:


In the project properties, you can add a pre-build event command line to get a copy of the dacpac file.

Or you can just add it in the csproj :

<PropertyGroup>
  <PreBuildEvent>copy "$(SolutionDir)DatabaseProject\bin\$(ConfigurationName)\DatabaseProject.dacpac" "$(ProjectDir)\DatabaseProject.dacpac"</PreBuildEvent>
</PropertyGroup>

This will only work if the database project was built first, so you should add a dependency. Right clic on the solution and select Project Dependencies..., then select the main project and check that it depends on the Database project.



来源:https://stackoverflow.com/questions/21668184/how-to-include-created-database-project-created-dacpac-into-a-cs-project

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!