SQLCMD include all scripts in folder - sqlcmd

In my Post Deployment Script, I would like to include all script files in a folder using a wildcard like this:
:r .\$(ReleaseName)\*.sql
Is there a way to do this? I can't find any..

I got it working:
<MyFilesPath Include="$(ProjectDir)MyPath\*.sql"/>
<MyFiles Include="#(MyFilesPath->':r %22..\Scripts\%(filename)%(extension)%22%0D%0A', '')"/>
Then I include #MyFiles in my PostScript-file.

I took a different approach that was easier for me to understand.
I simply added code to the Pre-build event in the database project properties page that copies the script files into a single file. I call a bat file and pass in the project path as a parameter because it's much nicer to edit the file than trying to edit in that little textbox in the properties page.
$(ProjectDir)PreBuildEvent.bat "$(ProjectDir)"
I set the contents of the bat to this:
copy %ProjectDir%DbUpdateScripts\*-Pre.sql %ProjectDir%DbUpdateScripts\AllPreScripts.sql
copy %ProjectDir%DbUpdateScripts\*-Post.sql %ProjectDir%DbUpdateScripts\AllPostScripts.sql
Then just include those files in your actual pre and post deploy scripts.
:r .\DbUpdateScripts\AllPreScripts.sql
:r .\DbUpdateScripts\AllPostScripts.sql
And finally, add AllPreScripts.sql and AllPostScripts.sql to your .gitignore file if you have one to prevent them from getting added to source control.

Building upon #SAS answer, here is what I did to get this working using MSBuild. Basically, the idea is that we add a pre-build target that auto-generates a post-deployment script referencing all the scripts in the source folder.
In the .sqlproj add the following at the end of the file:
<Target Name="BeforeBuild">
<PropertyGroup>
<MyAutogeneratedScriptPath>$(ProjectDir)Scripts\Post-deployment\MyScript.autogenerated.sql</MyAutogeneratedScriptPath>
</PropertyGroup>
<ItemGroup>
<MyScriptsLocation Include="$(ProjectDir)Scripts\Post-deployment\RunAll_1\*.sql" />
<MyScriptsLocation Include="$(ProjectDir)Scripts\Post-deployment\RunAll_2\*.sql" />
</ItemGroup>
<WriteLinesToFile File="$(MyAutogeneratedScriptPath)" Lines="-- This is an auto-generated file, any changes made will be overwritten" Overwrite="true" />
<WriteLinesToFile File="$(MyAutogeneratedScriptPath)" Lines="#(MyScriptsLocation->':r %22%(FullPath)%22', '%0D%0A')" Overwrite="false" />
</Target>
And then in your main post-deployment script file, include the MyScript.autogenerated.sql file.
Also, you might also want to add *.autogenerated.sql to your .gitignore file.

Related

How to preserve custom web.config settings in GeneXus 16

When you build a GeneXus app, the .Net Generator produces the web.config file which gets deployed. I want to add some custom settings to the web.config file, for example URL rewrite rules, in such a way that they are not lost when the build process happens.
How or where would I do this in GeneXus?
Have you already taken a look at Build Events?
https://wiki.genexus.com/commwiki/servlet/wiki?39474,Build%20Events
You can program something that adds the URL rewrite rules to a web.config file maybe using XMLWriter and then add this program to the Post-build Events so it is executed after every GeneXus Build and the file is kept up to date.

Publish Gulp destination files with Visual Studio 2015

In the new Visual Studio 2015 and the Web Essentials plugin, they've removed the function to compile certain files like Less files. Instead they suggest to use Gulp tasks.
While I applaud this decision and understand how to configure Gulp to compile the Less files, but because this is not an ASP.NET 5 application, the new files are not automatically added to the project and as such do not get copied when using the Publish function of VS2015.
As I see it the only way to get these file to copy is to manually add them to the project. This seems a but counter intuitive, if you create a task to compile **/*.less you have to look in your entire project to find the generated css files and add them all manually.
Am I just doing something wrong or is this just the way it works now?
Don't add the files manually, it is pretty easy to add them with a target in your project file. This is how we do it and we also use the gulp-rev package which modifies our filename dynamically (so they will not be cached by a browser). Here is how our BeforeBuild target from our .csproj file looks like:
<Target Name="BeforeBuild">
<Exec Command="BeforeBuild.bat" WorkingDirectory="$(ProjectDir)" />
<ItemGroup>
<Content Include="Scripts\Output\**\*.js" />
<Content Include="Content\**\output\**\*.css" />
</ItemGroup>
</Target>
And in our case when we publish all the generated js files from Scripts\Output\all_folders\ will get published too even though they are not in the csproj (and the same for the generated css files)
For those who preferred the "Web Essentials" method of compiling Less, Sass and CoffeeScript files, Mads Kristensen has published a new VS 2015 extension named Web Compiler. Try it. Also see his Bundler & Minifier extension for additional functionality removed from Web Essentials.

What manifest visual studio is using to generate msdeploy package

I want to package a folder with msdeploy.exe to a zip destination at the end of CI process.
I run the following command line
msdeploy.exe -verb:sync -source:contentpath="C:\SampleWebApp" -dest:package="c:\SampleWebApp.zip" -declareParamFile="parameters.xml"
I also like the *.deploy.cmd and *.SetParameters.xml which msbuild generates when it spits out a deployment package. I renamed the one set of *.deploy.cmd and *.SetParameters.xml file and changed the content accordingly. to be able to run in deployment environment.
When I run *.deploy.cmd file it generates the folder "C:\SampleWebApp" rather than creating the iis app based on parameters provided in .SetParameter.xml.
After some investigation, I've found that the .cmd deploys to -dest:auto which is good. but apparently my package manifest inside the package indicates that this package is contentPath whereas packages generated by msbuild has more complex manifest in archive.xml inside package using iisApp provider.
Having looked at following post
http://blogs.msdn.com/b/webdev/archive/2013/01/09/real-scenario-folder-deployment-scenarios-with-msdeploy.aspx
I believe if I use -source:manifest="Package.xml" with right Package.xml the end result should be similar to VS package output
The I thought maybe the *.SourceManifest.xml is the manifest for the package. I used and it builds the package but when I want to deploy that to the using .deploy.cmd it complains about setAclUser
Error: A value for the 'setAclUser' setting must be specified when the
'setAcl' provider is used with a physical path.
Does anybody know that is the manifest msbuild uses?
To directly answer your question: the manifest is generated dynamically based on MsDeploySourceManifest MSBuild items.
You can make it use contentPath rather than iisApp by declaring DeployAsIisApp=false in your publish profile (or command line /p:DeployAsIisApp=false). This will also disable the setAcl providers.
If you want to keep iisApp, you can disable the ACL providers...
... being added to the package by declaring IncludeSetAclProviderOnDestination=false in your publish profile
... being deployed by passing /I:False to deploy.cmd
Following is the manifest template
<?xml version="1.0" encoding="utf-8"?>
<sitemanifest>
<iisApp path="[PATH1]"/>
</sitemanifest>
and Parameter.xml template
<parameters>
<parameter name="IIS Web Application Name" defaultValue="WEBSITENAME" tags="IisApp">
<parameterEntry kind="ProviderPath" scope="IisApp" match="^[PATH1ESCAPED]$" />
</parameter>
<!-- appSetting section-->
</parameters>
note: [PATH1] should be replaced with your folder path like C:\MY.FOLDER\WWW
and [PATH1ESCAPED] should be same path but escaped with postfix and prefix ^ $ like
^C:\MY.FOLDER\WWW$
Then you can call
"C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe" -verb:sync -source:manifest="Manifest.xml" -dest:package=%1 -declareParamFile="parameters.xml"
and %1 being folder path like C:\MY.FOLDER\WWW

Azure Worker Role configuration issue while using SlowCheetah with custom config

We are using Nlog as logging tool with our Worker Role of Azure app.
It requires NLog.config file. We installed "SlowCheetah - XML Transforms", and have two Debug/Release transforms).
Solution does get rebuild successfully.
But when I try to run, I am getting following error. (I used exact transformation for nolog.config in one of my Windows service app, and it is working fine there).
Error 163 The item "bin\Debug\NLog.config" in item list "OutputGroups"
does not define a value for metadata "TargetPath". In order to use
this metadata, either qualify it by specifying
%(OutputGroups.TargetPath), or ensure that all items in this list
define a value for this metadata. C:\Program Files
(x86)\MSBuild\Microsoft\VisualStudio\v10.0\Windows Azure
Tools\1.6\Microsoft.WindowsAzure.targets 2299 5 Insight.CloudWeb
I don't know if this is done by the SlowCheetah extension, but could you verify if your *.csproj file contains the AfterCompile target similar to this?
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<UsingTask TaskName="TransformXml"
AssemblyFile="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.Tasks.dll" />
<Target Name="AfterCompile" Condition="exists(’app.$(Configuration).config’)">
<TransformXml Source="NLog.config"
Destination="$(IntermediateOutputPath)$(TargetFileName).config"
Transform="NLog.$(Configuration).config" />
<ItemGroup>
<AppConfigWithTargetPath Remove="NLog.config"/>
<AppConfigWithTargetPath Include="$(IntermediateOutputPath)$(TargetFileName).config">
<TargetPath>$(TargetFileName).config</TargetPath>
</AppConfigWithTargetPath>
</ItemGroup>
</Target>
Take a look at Oleg's blog post .Config File Transformation under App.config File Transformation for more information.
I have a fix for this. Now you should be able to transform app.config as well as other XML files for Azure Worker Roles using SlowCheetah. Once I get the fix verified I will release the update to the VS gallery.
If you would like to try the fix you can download the updated VSIX at https://dl.dropbox.com/u/40134810/SlowCheetah/issue-44/SlowCheetah-issue-44.zip. If you are interested in following up on this please use the issue #44.

Script Task - Add existing file as link

I've been looking for an answer to this for a bit now but couldn't find anything. I was wondering if it is possible to add an existing file to the project created under the script task in an SSIS package. What I want to be able to do is to add one file called Helper or Utility to the solution and then add that file to all the script tasks for common functions. This is so if I change the class, it gets pushed through to all script tasks.
I know that I can add a reference to a DLL and add it to the GAC. I have tried this and it works. I've also tried adding the file to the projects and that works too.
This is just another solution that I'm trying, just in case I'm not able to deploy the DLL in prod. Any help will be appreciated. Thanks.
Firstly you need a master copy of your classes, you can copy them from an existing Script Task using the same process below but in reverse.
Open the Editor for the Script Task and on the Property Explorer click on the Project File (the st_[Guid] ), in the Properties window you’ll see the Project Folder location. (This location gets recreated every time you edit the script task)
In explorer, copy your classes to this folder
On the Project Explorer, click on the “Show All Files” icon
Right click on your files and add to Project
You can use regular VS functionality for linking files:
Right click your script project
Add > Existing item...
Select files to be included in your project
In the bottom right corner of the Open file dialog box you have a drop-down with 2 options: "Add" or "Add As Link" - select the latter one and you are done (see image below)
We can not use relative path after adding pages using Add link. Each user need to correct the path before running the project. The script task uses its own path.it doesn't run from package path which is the problem.