Domanda

C'è un buon tutorial per la creazione di un database utilizzando msbuild

Jean Paul Boodhoo lo fa utilizzando Nant in questo post . egli imposta le proprietà da utilizzare in un file di costruzione 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>

quindi in grado di creare il database utilizzando il riga di comando come questo ..

c:\> build builddb

Ho installato il pacchetto MSBuild estensione, ma non riuscivo a trovare dove inserire la stringa di connessione per la connessione al database

Grazie

RISOLTO

 <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>

e Constants.proj assomiglia a questo

<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>

poi presso la pista prompt dei comandi vs

  

msbuild db.targets / t: QueryDb

il comando che viene eseguito è questo "C: \ Programmi \ Microsoft SQL Server \ 90 \ Tools \ Binn \ osql.exe" U someuser -P unapassword -d NorthwindTest -S (locale) \ SQLEXPRESS -Q "SELECT * FROM ProfiloUtente"

Grazie Sayed

È stato utile?

Soluzione

Se hai dimestichezza con l'approccio seguito in questo post, allora si può semplicemente seguire che da MSBuild pure. Per esempio creare il file constants.proj (è possibile il nome come volete) e db.targets (anche il nome è quello che volete). E poi quelli conterrebbe qualcosa come:

constants.proj

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <sqlToolsFolder>C:\Program Files\Microsoft SQL Server\90\Tools\Binn</sqlToolsFolder>
    <osqlConnectionString>-E</osqlConnectionString>
    <initialCatalog>Northwind</initialCatalog>
    <configConnectionString>data source=(local);Integrated Security=SSPI;Initial Catalog=$(initialCatalog)</configConnectionString>
    <databasePath>C:\root\development\databases</databasePath>
    <osqlExe>$(sqlToolsFolder)\osql.exe</osqlExe>
  </PropertyGroup>
</Project>

E poi nel db.targets si sarebbe solo costruire la linea di comando con quelle proprietà e utilizzare il compito Exec per eseguirlo, come il seguente.

db.targets

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="constants.targets"/>

  <Target Name="CreateDb">

    <PropertyGroup>
      <_Command> ... FILL IN HERE ... </_Command>
    </PropertyGroup>

    <Exec Command="$(_Command)" />

  </Target>

</Project>

Altri suggerimenti

La confezione MSBuild estensione contiene le attività (vale a dire MSBuild.ExtensionPack.Sql2005 e MSBuild.ExtensionPack.Sql2008) per manipolare database SQL e il seguente esempio:

<!-- Create a database -->
<MSBuild.ExtensionPack.Sql2005.Database TaskAction="Create" DatabaseItem="ADatabase2" MachineName="MyServer\SQL2005Instance"/>
<!-- Create the database again, using Force to delete the existing database -->
<MSBuild.ExtensionPack.Sql2005.Database TaskAction="Create" DatabaseItem="ADatabase2" Force="true" Collation="Latin1_General_CI_AI" MachineName="MyServer\SQL2005Instance"/>
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top