使用msbuild创建sql数据库
有没有关于使用 msbuild 创建数据库的好教程?
jean paul boodhoo 在 这篇 文章中使用 nant 来完成此操作。 他设置要在 nant 构建文件中使用的属性
<properties>
<property name="sqlToolsFolder" value="C:\Program Files\Microsoft SQL Server\90\Tools\Binn"/>
<property name="osql.ConnectionString" value="-E"/>
<property name="initial.catalog" value="Northwind"/>
<property name="config.ConnectionString" value="data source=(local);Integrated Security=SSPI;Initial Catalog=${initial.catalog}"/>
<property name="database.path" value="C:\root\development\databases" />
<property name="osql.exe" value="${sqlToolsFolder}\osql.exe" />
</properties>
,然后可以使用命令行创建数据库,如下所示。
c:\> build builddb
我安装了 MSBuild 扩展包,但找不到在哪里输入连接字符串进行连接到数据库
感谢
已解决
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="constants.proj"/>
<Target Name="QueryDb">
<PropertyGroup>
<_Command>-Q "SELECT * FROM Users"</_Command>
<_Command2>-i test.sql</_Command2>
</PropertyGroup>
<Exec Command="$(sqlcmd) $(_Command)" /><!---->
</Target>
</Project>
,Constants.proj 看起来像这样
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<sqlToolsFolder>C:\Program Files\Microsoft SQL Server\90\Tools\Binn</sqlToolsFolder>
<initialCatalog>NorthwindTest</initialCatalog>
<serverInstance>(local)\SQLEXPRESS</serverInstance>
<configConnectionString>data source=$(serverInstance);Integrated Security=SSPI;Initial Catalog=$(initialCatalog)</configConnectionString>
<osqlExe>"$(sqlToolsFolder)\osql.exe"</osqlExe>
<sqlcmd>$(osqlExe) -U someuser -P somepassword -d $(initialCatalog) -S (local)\SQLEXPRESS</sqlcmd>
<!--<sqlcmd>$(osqlExe) -E -d $(initialCatalog) -S (local)\SQLEXPRESS</sqlcmd>-->
</PropertyGroup>
</Project>
,然后在 vs 命令提示符下运行
msbuild db.targets /t:QueryDb
运行的命令是这样的 “C:\ Program Files \ Microsoft SQL Server \ 90 \ Tools \ Binn \ osql.exe”-U someuser -P somepassword -d NorthwindTest -S(本地)\ SQLEXPRESS -Q“从用户配置文件中选择*”
谢谢 赛义德
Is there a good tutorial for Creating a database using msbuild?
jean paul boodhoo does it using nant in this post.
he sets properties to be used in an nant build file
<properties>
<property name="sqlToolsFolder" value="C:\Program Files\Microsoft SQL Server\90\Tools\Binn"/>
<property name="osql.ConnectionString" value="-E"/>
<property name="initial.catalog" value="Northwind"/>
<property name="config.ConnectionString" value="data source=(local);Integrated Security=SSPI;Initial Catalog=${initial.catalog}"/>
<property name="database.path" value="C:\root\development\databases" />
<property name="osql.exe" value="${sqlToolsFolder}\osql.exe" />
</properties>
then can create the database using the command line like this..
c:\> build builddb
I installed the MSBuild Extension pack but I could not find where to enter the connection string to connect to the database
Thanks
RESOLVED
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="constants.proj"/>
<Target Name="QueryDb">
<PropertyGroup>
<_Command>-Q "SELECT * FROM Users"</_Command>
<_Command2>-i test.sql</_Command2>
</PropertyGroup>
<Exec Command="$(sqlcmd) $(_Command)" /><!---->
</Target>
</Project>
and Constants.proj looks like this
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<sqlToolsFolder>C:\Program Files\Microsoft SQL Server\90\Tools\Binn</sqlToolsFolder>
<initialCatalog>NorthwindTest</initialCatalog>
<serverInstance>(local)\SQLEXPRESS</serverInstance>
<configConnectionString>data source=$(serverInstance);Integrated Security=SSPI;Initial Catalog=$(initialCatalog)</configConnectionString>
<osqlExe>"$(sqlToolsFolder)\osql.exe"</osqlExe>
<sqlcmd>$(osqlExe) -U someuser -P somepassword -d $(initialCatalog) -S (local)\SQLEXPRESS</sqlcmd>
<!--<sqlcmd>$(osqlExe) -E -d $(initialCatalog) -S (local)\SQLEXPRESS</sqlcmd>-->
</PropertyGroup>
</Project>
then at the vs command prompt run
msbuild db.targets /t:QueryDb
the command that runs is this
"C:\Program Files\Microsoft SQL Server\90\Tools\Binn\osql.exe" -U someuser -P somepassword -d NorthwindTest -S (local)\SQLEXPRESS -Q "SELECT * FROM UserProfile"
Thank you
Sayed
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您对该帖子中采用的方法感到满意,那么您也可以简单地遵循 MSBuild 中的方法。例如,创建文件constants.proj(您可以将其命名为任何您喜欢的名称)和db.targets(也可以将其命名为您想要的任何名称)。然后它们将包含类似以下内容:
constants.proj
然后在 db.targets 中,您只需使用这些属性构建命令行并使用 Exec 任务来执行它,如下所示。
db.targets
If you are comfortable with the approach followed in that post then you can simply follow that from MSBuild as well. For example create the file constants.proj (you can name it whatever you like) and db.targets (also name it whatever you want). And then those would contain something like:
constants.proj
And then in db.targets you would just build the command line with those properties and use the Exec task to execute it, like the following.
db.targets
MSBuild 扩展包包含用于操作 SQL 数据库的任务(即
MSBuild.ExtensionPack.Sql2005
和MSBuild.ExtensionPack.Sql2008
)以及以下示例:The MSBuild Extension pack contains tasks (namely
MSBuild.ExtensionPack.Sql2005
andMSBuild.ExtensionPack.Sql2008
) to manipulate SQL databases and the following example: