如何将创建的数据库项目创建的dacpac包含到CS项目中 [英] How to include created database project created dacpac into a cs project

查看:143
本文介绍了如何将创建的数据库项目创建的dacpac包含到CS项目中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个单独的数据库项目,我想在同一解决方案中进行构建,然后引用创建的dacpac.当我尝试添加数据库项目时,它构建良好,并且dll被添加到了辅助项目文件中,但dacpac却没有.

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.

是否可以通过msbuild将dacpac复制到主项目中?我一直认为应该有一种方法可以修改sqlproj文件或csproj文件,以便将dacpac包含为项目输出之一.我对msbuild的了解并不广泛,我无法弄清楚.

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.

在我看来,我需要以某种方式添加dacpac来表示"@(ReferenceCopyLocalPaths)"项,但我无法弄清楚.任何提示或建议,将不胜感激.

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.

我尝试做一些类似于此处引用的操作 MSBuild-通过执行以下操作

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>

不会为DacPacs提供任何内容(添加通配符时).我也尝试引用sqlproj文件中的项目组之一,但它对以下内容为空:

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:

推荐答案

在项目属性中,您可以添加构建前事件命令行以获取dacpac文件的副本.

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

或者您可以将其添加到csproj中:

Or you can just add it in the csproj :

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

这仅在首先构建数据库项目的情况下才有效,因此您应该添加一个依赖项.右键单击该解决方案,然后选择Project Dependencies...,然后选择主项目并检查它是否依赖于Database项目.

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.

这篇关于如何将创建的数据库项目创建的dacpac包含到CS项目中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆