In Visual Studio 2010 there is a nice feature of the database project that allows you to deploy to a database as well as set up various environments based on your configuration (Build deploy etc)
I Would like to integrate this into our automated build environment.
Firstly by having the deploy script run after a successful build on my local machine. (So I can go straight into running the unit tests)
Then by Having the deploy script run after the successful build on our build server. so that any schema changes required for the unit and integration tests will run.
How can I adjust the MSBuild or similar to run these in deploy mode.
Use the MSBuild task to call the "dbproj" file. Pass "DBDeploy" as the target and the build configuration as a property, e.g.:
<MSBuild Projects="MyDb.dbproj"
Targets="DBDeploy"
Properties="Configuration=$(Configuration)" />
On a build server, you might also need to supply properties like TargetConnectionString and TargetDatabase.
Related
I'm assessing moving from TeamCity to VSTS and there are two steps I have in my pipeline that I'm not sure how to setup in VSTS.
How do I include 3rd party dlls in my build? Currently we use a tool that must be installed in the Developer's computers that has separate dlls for x86 and x64. The x86 are included in the project and are needed for the designer, but the x64 are copied from the Program Files folder with an after-build command in Visual Studio. For it to work in TeamCity the tool was installed in the server, so the same after-build command copies the dlls into the build directory as in any other developer computer.
I don't see a way to achieve this in VSTS without including the x64
dlls in the source code, which isn't desirable due to the tool's
license.
How do I publish to SVN? Currently our binaries are hosted in an SVN server. In TeamCity I have a PowerShell script that (in short) updates the SVN local repo in the server, copies all the files from the build directory into the SVN repo and commits the changes.
Storing your dependencies
Lot's of options available here:
Put them in a NuGet package and store them in VSTS Package Management. Have your build restore the package during build.
Put them in Source control, either SVN or TFVC and fetch them during the build.
Store them in Azure Blob storage and fetch them on-demand by downloading them at the start of your build.
Use a custom build agent (Azure VM?) and install the software and the VSTS build agent onto it.
Store them as Build Artefacts in one Build Definition and fetch them using the Fetch Build Artefacts task, which is available from the marketplace.
I'm not sure what kind of license issues you're facing, but I'd expect that each has the same issues if you're not allowed to put the binaries anywhere other than on a licensed machine. Maybe the vendor offers a better option or can be persuaded to offer a Cloud/VM license option.
Publish to SVN
I don't see why the same PowerShell script couldn't be used. Though I'd recommend not to alter your repository from the build pipeline. It makes future CI/CD scenarios much harder. You can attach the binaries as Artefacts to VSTS Builds and that way they can also easily be linked to Release pipelines. You may need to fetch the latest version of svn and store it somewhere in order to run your script. When running on a Azure VM, you can simply install SubVersion directly to the agent.
There is no built-in task available.
One of our customers uses Visual Studio Online ( http://www.visualstudio.com/en-us/products/what-is-visual-studio-online-vs.aspx ) which is based on capabilities of Team Foundation Server (TFS)
We were researching how to do automated Builds and automated Unit Tests using the Visual Studio Online account.
Using Visual Studio 2012 IDE, I was able to setup a build in the Hosted Build Service. However, my Unit Tests need a Microsoft SQL Server Database to run properly, which I have installed on my development workstation.
In order to run my tests I need to have my database running in a SQL instance on the build agent.
Is it possible to install SQL server on the Hosted Build Agent, and if so, how?
It is not possible to add non-standard capabilities to a hosted build agent. You are assigned a clean pre-built VM with all of the standard pre-requisite for compiling binaries and running unit tests. As integration tests, what you are describing above, require an instance of your application you can't run them there.
Here are the options that you have in order of recommendation:
1 - Re-write your tests as Unit and not Integration
The tests that you are describing above do not meet the standard definition of "Unit Test". You can use mocking, stubs, and other testing techniques to decouple your tests from the database so that they are only testing a single unit of functionality rather than the integration between your code and the database. Having sets of tests for each will better help you isolate the route cause of the issue and more quickly fix it at less cost to your customer. It will also aid in the reduction of bugs and other issues that can be introduced over time.
Large complicated integration tests should be kept to a minimum as it increases the amount of time required to support them and maximises the cost to your customer.
One obviously needs integration tests at some point and option #2 is the best for running integrations.
2 - Use Release Management to deploy and test
You can setup a VM to host a working version of your application and use Release Management to deploy the instance then execute your Integration Tests there. If you use the VSO hosted Release Management server you are limited to Azure VM's as targets. If you deploy your own RM server then you need to manage that as well. I would and do use the hosted RM.
The bit we care about is the DevOps bit on the right. Any time you need an instance of your application it should be deployed correctly separately from your build server.
http://nakedalm.com/create-release-management-pipeline-professional-developers/
Once you have your application deployed it is fairly simple to get the integration tests you want executing against the instance.
http://blogs.msdn.com/b/visualstudioalm/archive/2014/11/11/deploying-and-testing-web-applications-using-release-management.aspx
If you download the example from the link above it has a powershell for executing the tests in the environment.
3 - Setup your own agent and controller
You can create your own build controller & agent attached to the VSO account and build the app yourself. Most folks create an Azure VM with all of the bits they need and run there. This is your server that you will need to manage and pay for. You can also use a local server.
Note: This is the wrong approach as an instance of your application should not be available on a build server. A build server is for compiling your binaries and running actual Unit Tests, not integration or UI tests.
Thanks for all your help.
I contacted #tamasf who is one of the developers for the Effort Testing Tool for Entity Framework, and he told me that Effort Testing Tool only needs to know about he EDMX file in order mock Entity Framework ( which means Database won't need to be up and running, therefore, allowing us to follow proper Unit testing practices ) For more information, please read the following post: How would I configure Effort Testing Tool to mock Entity Framework's DbContext withOut the actual SQL Server Database up and running?
I have been doing some work recently with publishing mvc applications on visual studio 2012. I have been using publish profiles to configure web deploy to different environments. I have also been using web transforms to transform my web.config as per each of my publish profiles.
In a package, is there a setting to ensure the server its getting installed on wipes previous installed content from the previous install?
As an aside from the above, is it possible to package an application and not have it perform the transforms until gets deployed? Therefore the package is independent of the target server (dev, qa) and can installed on either.
You can deploy an existing package using publish profiles with some custom MSDeploy magic. However, I've not tried to hold onto web.config transforms and gone with MSDeploy parameters completely. It's worth attempting, but I've not tested my custom script with them so there may be some targets that I've forgotten.
I still use web.config transforms, but only to remove non-debug elements when creating the package (with a Release transform)
We have recently migrated to using the Visual Studio database projects. What we want to do is for the database to deploy when the TFS build server builds.
This is relatively simple and we have this working for a single database, however, what we need is for it to deploy to multiple database as we have a SaaS product with multiple databases. So for example, when we do a QA build, all the different databases with various configurations on the QA DB server should be updated.
Is there a 'proper' way to do this?
Our current plan is to take the deployment .sql script that will be generated from the database configured for deployment, then create a custom build task which runs this script against the rest of the databases.
I don't think there is a standard way of doing this, so we created a custom build task that iterates over the databases we want to deploy to executing the deployment script generated by the standard database project's deploy against each DB.
We have a system consisting of a winforms client, a bunch of web services, a bunch of reporting services reports and a database with a corresponding database project in VS 2010.
We use TFS as source control system and for automatic builds etc.
When our tester queues a new build from within the Build Explorer, our client and server is build and the server is deployed to the web server. Reports and database changes are not deployed automatically.
Is it possible to have the changes from the database project deployed automatically to the test database whenever a new test build is queued?
Yes.
Your build template can invoke VSDBCMD.exe to do a comparison between your database project (.dbschema) and your test database in order to generate and execute a script that will update your test database.
Here is info about VSDBCMD.
Here is the procedure to setup your build template to use VSDBCMD.