How to execute Oracle utility in MSBuild - oracle

I want to execute the oracle's import utility in MSBuild as a task. Please give a detailed answer. I am a beginner.

You may want to look into the MSBuild Exec task. I am not familiar with the Oracle utility you specified, but I do know that the Exec task will run most anything that can be run from a command line. The relevant MSBuild configuration you would need might looks something like this:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="DoImport">
<Exec
Command="imp SYSTEM/password FILE=dba.dmp FROMUSER=scott TABLES=(dept,emp)" />
</Target>
</Project>

A somewhat more long-winded but better solution is to develop a custom Task that extends the ToolTask base class. This will allow better logging and you can define the arguments by using specific XML attributes.
I've developed one for SqlPlus and it works really well.

Related

Adding project to solution through command line

I have a Visual studio solution that is made up of multiple test projects. Each project is a copy of a template project. When the template project is copied there is a batch script that is ran that does some file renamings and adds a couple other specified files. What i would like to do is then have the project added to the solution during that process. I was looking at devenv switches here on MSDN but i am not seeing anything about adding a project to a solution.
Is adding a project to a solution possible through the command line?
Thanks
If you are here after 2019 and using Asp.Net Core. Here is the way to do it:
dotnet sln yoursolution.sln add yourprojectpath/yourproject.csproj
If you don't mind writing a bit of PowerShell, you can do this pretty easily. First, read this question and its answers. You'll find a pointer to a nuget package (Microsoft.SQLServer.Compact) which includes PowerShell scripts to automate VS through its object model. This is a good place to start to have some examples of how to handle a solution file from PowerShell. Then you write a small PowerShell script using the SolutionFolder.AddFromFile to add your project to your solution. This might be even easier using StudioShell and its provider, but I haven't tried it yet.
For sln file try this question. For project file you can run some xslt or any other necessary transform to edit. For example you can create MSBuild proj file to run xslt transform over desired sln file and then run it in cmd like: MSBuild.exe MyProj.proj. The sample content of MyProj.proj is like:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="Transform">
<TransformXml Source="Project.csproj" Transform="Transform.xml" Destination="New_Project.csproj" />
</Target>
</Project>

how to automated a BUILD task

I need help about how to automated a task with MSBUILD.
I wrote a small command line program that process files and I want integrate it at the moment of BUILD the solution.
The program itself is used like this:
Processor.exe inputFile.txt outputFile.txt –p
-p of course represents some parameters.
Is there a simple way to make visual studio to run this exe AFTER each Buildup??
To be honest I research a lot about the MSBUILD, but there is so much information out there, that it overwhelmed me.
There are different solutions but in your case the best is probably with custom AfterBuild target and Exec task. You should add it to your cproj file after Microsoft.CSharp.targets get imported.
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name ="AfterBuild">
<Exec Command="Processor.exe inputFile.txt outputFile.txt –p" />
</Target>
You can read more about Exec Task here:
Exec Task

How do I tell MSTEST to run all test projects in a Solution?

I need to know how to tell MSTEST to run all test projects in a solution file. This needs to be done from the command line. Right now I have to pass it a specific project file, I'm trying to get it to run from a SOLUTION file.
I'm hoping this is possible, because in Visual Studio, hitting Ctrl+R, A, runs ALL tests in the currently opened solution.
The way I've interpretted the help files, you have to pass in each DLL specifically.
I want to run this from the command line from my CruiseControl.NET server, so I can write other utilities to make this happen. If there is a wierd way of getting this to happen through some OTHER method, let me know.
How do I tell MSTEST to run all test projects for a solution?
<exec>
<!--MSTEST seems to want me to specify the projects to test -->
<!--I should be able to tell it a SOLUTION to test!-->
<executable>mstest.exe</executable>
<baseDirectory>C:\projects\mysolution\</baseDirectory>
<buildArgs>/testcontainer:testproject1\bin\release\TestProject1.dll
/runconfig:localtestrun.Testrunconfig
/resultsfile:C:\Results\testproject1.results.trx</buildArgs>
<buildTimeoutSeconds>600</buildTimeoutSeconds>
</exec>
To elaborate on VladV's answer and make things a bit more concrete, following the suggested naming convention running your tests can be easily be automated with MSBuild. The following snippet from the msbuild file of my current project does exactly what you asked.
<Target Name="GetTestAssemblies">
<CreateItem
Include="$(WorkingDir)\unittest\**\bin\$(Configuration)\**\*Test*.dll"
AdditionalMetadata="TestContainerPrefix=/testcontainer:">
<Output
TaskParameter="Include"
ItemName="TestAssemblies"/>
</CreateItem>
</Target>
<!-- Unit Test -->
<Target Name="Test" DependsOnTargets="GetTestAssemblies">
<Message Text="Normal Test"/>
<Exec
WorkingDirectory="$(WorkingDir)\unittest"
Command="MsTest.exe #(TestAssemblies->'%(TestContainerPrefix)%(FullPath)',' ') /noisolation /resultsfile:$(MSTestResultsFile)"/>
<Message Text="Normal Test Done"/>
</Target>
Furthermore integrating MsBuild with CruiseControl is a piece of cake.
Edit
Here's how you can 'call' msbuild from your ccnet.config.
First if you do not already use MSBuild for your build automation add the following xml around the snippet presented earlier:
<Project DefaultTargets="Build"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
..... <insert snippet here> .....
</Project>
Save this in e.g. RunTests.proj next to your solution in your source tree. Now you can modify the bit of ccnet.config above to the following:
<msbuild>
<executable>C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\MSBuild.exe</executable>
<workingDirectory>C:\projects\mysolution\</workingDirectory>
<baseDirectory>C:\projects\mysolution\</baseDirectory>
<projectFile>RunTests.proj</projectFile>
<targets>Test</targets>
<timeout>600</timeout>
<logger>C:\Program Files\CruiseControl.NET\server\ThoughtWorks.CruiseControl.MsBuild.dll</logger>
</msbuild>
This is an old thread, but I have been struggling with the same issue and I realized that you can really just run MSTest on every dll in the whole solution and it doesn't really cause any problems. MSTest is looking for methods in the assemblies marked with the [TestMethod] attribute, and assemblies that aren't "test" assemblies just won't have any methods decorated with that attribute. So you get a "No tests to execute." message back and no harm done.
So for example in NAnt you can do this:
<target name="default">
<foreach item="File" property="filename">
<in>
<items>
<include name="**\bin\Release\*.dll" />
</items>
</in>
<do>
<echo message="${filename}" />
<exec program="C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\MSTest.exe">
<arg value="/testcontainer: ${filename}" />
<arg value="/nologo" />
</exec>
</do>
</foreach>
</target>
and it will run all the test methods in every dll in every bin\Release folder in the solution. Those which are not test dlls will return a "No tests to execute." and those that have tests will have the tests run. The only part I haven't figured out yet is that (in NAnt) execution stops the first time a command returns a non-zero value. So if any unit tests fail it doesn't keep going to execute any tests in subsequent assemblies. That is not great, but if all the tests pass, then they will all run.
I just resolve this problem recently. Here is my proposal: Use testmetadata + testlist option of mstest
First you should create a testlist in testmetadata file(vsmdi)
the commandline should be mstest /testmetadata:....vsmdi /testlist:<name>
Then use ccnet config to run mstest
i know this thread is quite Old, but its still high on Google so i thought i might help one or two.
Anyway, since there is no satisfactory solution for this.
I've written an msbuild task for this.
details can be found here:
http://imistaken.blogspot.com/2010/08/running-all-tests-in-solution.html
You could enforce some convention on the naming and location of test projects, then you could run MSTest on, say, all *Test.dll below the location of your solution.
As far as I know, there is no way to tell a test project from a 'normal' DLL project based soleley on a solution file. So, an alternative could be to analyze the project files and/or .vsmdi files to find the test projects, but that could be rather tricky.
I don't know directly but this is where VSMDI [fx:spits in a corner] can help. In your solution add all the tests to the VSMDI. And then pass the VSMDI to mstest using /testmetadata.
However I would suggest that you follow the conventions above. And use a naming convention and dump that out from the SLN file using say a for loop in the command script
I would just write a target that calls it the way you want, then whip up a batch file that calls the target that contains all the DLL's to be tested.
Unless you're adding test projects all the time, you'll very rarely need to modify it.
Why not just have msbuild output all the test assemblies to a folder.
Try setting OutputPath,OutputDir,OutDir properties in msbuild to accomplish this.
then have mstest execute against all assemblies in that folder.

How to copy a build to test server?

Hope someone can assist me with this. Have TeamCity up and running and doing builds on various projects. I'd like to be able to copy/deploy a successful TeamCity ran build to a test server automatically.
I was thinking of using PowerShell to do this but, am open to other ideas. Can some provide me with info on how I can accomplish this.
Thanks.
I use WGet. Here are the instructions for forming the team city URL. You can do a WGet in powershell, but if you only wanted powershell for this functionality, you can just use a plain wget utility for windows.
EDIT: Here is an example from our QA deployment (names changed to protect the guilty):
"C:\Program Files (x86)\NcFTP\wget.exe" "http://teamcityserver.domain.com:8111/guestAuth/repository/download/bt6/.lastFinished/Artificat.ear"
The location of the wget isn't relevant, that is just where it happens to be. The guestAuth part of the parameter specifies the authentication type (in our case we enabled guest authorization to not have to bother with passwords - it is an internal server only anyway and protected by firewalls). The options are in the documentation I linked to.
The other interesting feature of the parameters is the bt6. That is the unique key of the build, and is different for every project. You can discover what it is by navigating the team city website to the configuration of that build - it will be there. There are also instructions for referencing the configuration by name, but we found that was too verbose to bother with.
I've been implementing this for our applications today. Using msbuild. I have found this very useful as we can add in custom steps such as modifying config files, archiving live builds and notifying people of changes.
Here is a build script you may find useful. It precompiles the application and then copies it into the deploy directory.
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Deploy">
<PropertyGroup>
<WebsitePublishDirectory>Artifacts\Website</WebsitePublishDirectory>
<WebsiteDeployDirectory>\\SERVERNAME\Path\to\web\root</WebsiteDeployDirectory>
<WebsiteProject>[Project name here]</WebsiteProject>
</PropertyGroup>
<Target Name="Deploy">
<RemoveDir Directories="$(WebsitePublishDirectory)" />
<AspNetCompiler
VirtualPath="test"
PhysicalPath="$(WebsiteProject)"
TargetPath="$(WebsitePublishDirectory)"
Force="true"
Debug="false" />
<ItemGroup>
<PublishedFiles Include="$(WebsitePublishDirectory)\**" />
</ItemGroup>
<Copy SourceFiles="#(PublishedFiles)" DestinationFolder="$(WebsiteDeployDirectory)\%(RecursiveDir)" />
</Target>
</Project>
You could also install a TeamCity agent on the test server. That's actually how TeamCity was intented to be used.
I created a Post Build Script in Visual Studio like this:
c:\TeamCityBuild\pt_build.bat
exit 0
Then on the TC-server I have a .bat that looks like this:
net use r: \192.168.16.85\WebSite password /USER:domain.com\administrator
xcopy "C:\TeamCityBuild\path\WebSite*" "r:\" /R /Y /E
r: \192.168.16.85\WebSite /DELETE
if errorlevel 1 goto buildFAILED
:buildOK
echo Wehej!!!
exit 0
:buildFAILED
echo Oh NOOO!!!
exit 1
'R:' is a mapped drive to the test server.
The error handling is only needed to avoid script errors when someone builds the project on a environment without the correct folder structure.
So far everyting is working great!

Can you use CruiseControl to build Cocoa/Objective-C projects?

Has anyone ever set up Cruise Control to build an OS X Cocoa/Objective-C project?
If so, is there a preferred flavor of CruiseControl (CruiseControl.rb or just regular CruiseControl) that would be easier to do this with.
I currently have a Ruby rake file that has steps for doing building and running tests, and wanted to automate this process after doing a checkin.
Also, does CruiseControl have support for git? I couldn't find anything on the website for this.
Yes, you just run xcode builds via the command line (xcodebuild) which makes it simple to target from CC via an ant <exec>. I've been using just regular CC, not the ruby version and it works fine. Here's a barebones example:
<project name="cocoathing" default="build">
<target name="build">
<exec executable="xcodebuild" dir="CocoaThing" failonerror="true">
<arg line="-target CocoaThing -buildstyle Deployment build" />
</exec>
</target>
</project>
More info on xcodebuild
And there does appear to be a standard git object here, but I don't use git so I can't tell you much more than that!
Yes, CruiseControl has a support for git.

Resources