I have created 10 different packages and i want to execute them from c# coding. Can some one post some screen shots to achieve this.
I have tried this
Application app = new Application();
TraceService("loading system From File system");
//Create package Container to hold the package.
//And Load the Package Using the Application Object.
Package package = app.LoadPackage(#"C:\User\Kiran\Documents\Visual Studio 2012\Projects\WindowsServiceTest\WindowsServiceTest\Package1.dtsx", null);
TraceService("Execution Started");
DTSExecResult result = package.Execute();
// print the result
TraceService(result.ToString());
TraceService("Execution Completed");
Here i have to get the file name in run time not by hard coding
Following code will execute all packages from given folder.
var pkgLocation = #"C:\User\Kiran\Documents\Visual Studio 2012\Projects\WindowsServiceTest\WindowsServiceTest\";
foreach (var file in Directory.EnumerateFiles(pkgLocation, "*.dtsx"))
using (var pkg = new Application().LoadPackage(file, null))
{
var pkgResults = pkg.Execute();
Console.WriteLine("Package File Name:{0}, Result:{1}",file.ToString(), pkgResults.ToString());
}
The executing SSIS package from C# and VB is well documented in official site. This is my complete code in script task to execute multiple SSIS packages.
string packagesFolder = Dts.Variables["User::packagesFolder"].Value.ToString();
string rootFolder = Dts.Variables["User::rootFolder"].Value.ToString();
Package pkg;
Microsoft.SqlServer.Dts.Runtime.Application app;
DTSExecResult pkgResults;
foreach (var pkgLocation in Directory.EnumerateFiles(packagesFolder+"\\", "ValidateDataMigration-*.dtsx"))
{
try
{
app = new Microsoft.SqlServer.Dts.Runtime.Application();
pkg = app.LoadPackage(pkgLocation, null);
pkgResults = pkg.Execute();
File.AppendAllText(rootFolder + "\\DataValidationProgress.log", pkgLocation.ToString()+"=>"+ pkgResults.ToString()+ Environment.NewLine);
}
catch(Exception e)
{
File.AppendAllLines(rootFolder + "\\DataValidationErrors.log", new string[] { e.Message, e.StackTrace });
}
}
Related
.nunit files are not running when using NUNIT in C#
I have tried running below code, but the error returned is that the file is not supported. All the examples on the internet use .dll as the path for a testpackage, not .unit.
According to below sites, it is possible to run .unit files:
https://github.com/nunit/docs/wiki/Writing-Engine-Extensions and
https://github.com/nunit/nunit-project-loader/tree/master/src/extension
var path = #"path to nunit file";
var package = new TestPackage(path);
var engine = TestEngineActivator.CreateInstance();
using (var runner = engine.GetRunner(package))
{
var result = runner.Run(this, TestFilter.Empty);
}
}
I have tried the following by referencing nunitprojectloader dll:
var path = #"C:\Users\Administrator\Desktop\nunit-project-loader-master\nunit-project-loader-master\ConsoleApplication1\bin\Debug\DEV.nunit";
NUnitProjectLoader pl = new NUnitProjectLoader();
pl.LoadFrom(path);
var package = pl.GetTestPackage(path);
var engine = TestEngineActivator.CreateInstance();
using (var runner = engine.GetRunner(package))
{
// execute the tests
var result = runner.Run(this, TestFilter.Empty);
}
There is a new error by doing this:
It tries running NBi.NUnit.Runtime.dll which is referenced in the nunit file.
Everythings works fine using the console.
MSBuildWorkspace does now show documents on computers other than the one I'm using to build the application.
I have seen Roslyn workspace for .NET Core's new .csproj format, but in my case, it works fine on the development computer (Documents is populated), but it is empty for the same project on a different computer.
So I am not sure why it would work on my development computer, but not on my other computer...?
This is the code :
public static IReadOnlyList<CodeFile> ReadSolution(string path)
{
List<CodeFile> codes = new List<CodeFile>();
using (MSBuildWorkspace workspace = MSBuildWorkspace.Create())
{
var solution = workspace.OpenSolutionAsync(path).Result;
foreach (var project in solution.Projects)
{
//project.Documents.Count() is 0
foreach (var doc in project.Documents)
{
if (doc.SourceCodeKind == SourceCodeKind.Regular)
{
StringBuilder sb = new StringBuilder();
using (var sw = new StringWriter(sb))
{
var source = doc.GetTextAsync().Result;
source.Write(sw);
sw.WriteLine();
}
codes.Add(new CodeFile(doc.FilePath, sb.ToString()));
}
}
}
}
return codes;
}
It turns out that the newer versions of MSBuildWorkspace no long throw exceptions on failures, instead raising an event, WorkspaceFailure. (https://github.com/dotnet/roslyn/issues/15056)
This indicated that the required build tools (v15 / VS2017) were not available. The new 2017 Build Tools installer is both too complicated for our end users and much slower to install than the 2015 build tools installer was.
Instead, I came up with this less robust method to avoid that dependency:
public static IReadOnlyList<CodeFile> ReadSolution(string path)
{
List<CodeFile> codes = new List<CodeFile>();
var dirName = System.IO.Path.GetDirectoryName(path);
var dir = new DirectoryInfo(dirName);
var csProjFiles = dir.EnumerateFiles("*.csproj", SearchOption.AllDirectories);
foreach(var csProjFile in csProjFiles)
{
var csProjPath = csProjFile.Directory.FullName;
using (var fs = new FileStream(csProjFile.FullName, FileMode.Open, FileAccess.Read))
{
using (var reader = XmlReader.Create(fs))
{
while(reader.Read())
{
if(reader.Name.Equals("Compile", StringComparison.OrdinalIgnoreCase))
{
var fn = reader["Include"];
var filePath = Path.Combine(csProjPath, fn);
var text = File.ReadAllText(filePath);
codes.Add(new CodeFile(fn,text));
}
}
}
}
}
return codes;
}
I had same problem
I was using a .Net Core Console App.
I noticed that Microsoft.CodeAnalysis.Workspaces.MSBuild had the warning:
Package Microsoft.CodeAnalysis.Workspaces.MSBuild 2.10.0 was restored using '.Net Framework,version=v4.6.1' instead of the project target framework '.NetCoreApp,Version=v2.1'. this package may not be fully compatible with your project.
I changed to a .Net Framework Console App and I could access the documents.
Have been checking out Cake (at http://cakebuild.net) and am wondering if it can be used for deploying webapps and/or accessing virtual servers fro deploying of release packages.
I like the idea of cake being a deployment framework in C# so being in the same language as core development.
Are there any examples of azure deployments that I could get access?
There's a few ways you can deploy Azure using Cake, either through prebuilding site using some CI service like VSTS/AppVeyor and then publishing the artifacts using web deploy, git or ftp (there's a few Cake addins that can help with that Cake.WebDeploy, Cake.Git or Cake.FTP or using Azure built-in deployment engine Kudu and a custom deployment script using Cake.
To assist with the Kudu deploy/build environment you can use the Cake.Kudu addin.
The first step is to tell Kudu that you've got an custom deployment script, you do this by adding a ".deployment" file to the root of your repository with the content of
[config]
command = deploy.cmd
The deploy.cmd could look something like this to install & launch Cake
#echo off
IF NOT EXIST "Tools" (md "Tools")
IF NOT EXIST "Tools\Addins" (MD "Tools\Addins")
nuget install Cake -ExcludeVersion -OutputDirectory "Tools" -Source https://www.nuget.org/api/v2/
Tools\Cake\Cake.exe deploy.cake -verbosity=Verbose
And deploy.cake could look something like this:
#tool "nuget:https://www.nuget.org/api/v2/?package=xunit.runner.console"
#tool "nuget:https://www.nuget.org/api/v2/?package=KuduSync.NET"
#addin "nuget:https://www.nuget.org/api/v2/?package=Cake.Kudu"
///////////////////////////////////////////////////////////////////////////////
// ARGUMENTS
///////////////////////////////////////////////////////////////////////////////
var target = Argument<string>("target", "Default");
var configuration = Argument<string>("configuration", "Release");
///////////////////////////////////////////////////////////////////////////////
// GLOBAL VARIABLES
///////////////////////////////////////////////////////////////////////////////
var webRole = (EnvironmentVariable("web_role") ?? string.Empty).ToLower();
var solutionPath = MakeAbsolute(File("./src/MultipleWebSites.sln"));
string outputPath = MakeAbsolute(Directory("./output")).ToString();
string testsOutputPath = MakeAbsolute(Directory("./testsOutputPath")).ToString();
DirectoryPath websitePath,
websitePublishPath,
testsPath;
FilePath projectPath,
testsProjectPath;
switch(webRole)
{
case "api":
{
websitePath = MakeAbsolute(Directory("./src/Api"));
projectPath = MakeAbsolute(File("./src/Api/Api.csproj"));
testsPath = MakeAbsolute(Directory("./src/Api.Tests"));
testsProjectPath = MakeAbsolute(File("./src/Api.Tests/Api.Tests.csproj"));
websitePublishPath = MakeAbsolute(Directory("./output/_PublishedWebsites/Api"));
break;
}
case "frontend":
{
websitePath = MakeAbsolute(Directory("./src/Frontend"));
projectPath = MakeAbsolute(File("./src/Frontend/Frontend.csproj"));
testsPath = MakeAbsolute(Directory("./src/Frontend.Tests"));
testsProjectPath = MakeAbsolute(File("./src/Frontend.Tests/Frontend.Tests.csproj"));
websitePublishPath = MakeAbsolute(Directory("./output/_PublishedWebsites/Frontend"));
break;
}
case "backoffice":
{
websitePath = MakeAbsolute(Directory("./src/Backoffice"));
projectPath = MakeAbsolute(File("./src/Backoffice/Backoffice.csproj"));
testsPath = MakeAbsolute(Directory("./src/Backoffice.Tests"));
testsProjectPath = MakeAbsolute(File("./src/Backoffice.Tests/Backoffice.Tests.csproj"));
websitePublishPath = MakeAbsolute(Directory("./output/_PublishedWebsites/Backoffice"));
break;
}
default:
{
throw new Exception(
string.Format(
"Unknown web role {0}!",
webRole
)
);
}
}
if (!Kudu.IsRunningOnKudu)
{
throw new Exception("Not running on Kudu");
}
var deploymentPath = Kudu.Deployment.Target;
if (!DirectoryExists(deploymentPath))
{
throw new DirectoryNotFoundException(
string.Format(
"Deployment target directory not found {0}",
deploymentPath
)
);
}
///////////////////////////////////////////////////////////////////////////////
// SETUP / TEARDOWN
///////////////////////////////////////////////////////////////////////////////
Setup(() =>
{
// Executed BEFORE the first task.
Information("Running tasks...");
});
Teardown(() =>
{
// Executed AFTER the last task.
Information("Finished running tasks.");
});
///////////////////////////////////////////////////////////////////////////////
// TASK DEFINITIONS
///////////////////////////////////////////////////////////////////////////////
Task("Clean")
.Does(() =>
{
//Clean up any binaries
Information("Cleaning {0}", outputPath);
CleanDirectories(outputPath);
Information("Cleaning {0}", testsOutputPath);
CleanDirectories(testsOutputPath);
var cleanWebGlobber = websitePath + "/**/" + configuration + "/bin";
Information("Cleaning {0}", cleanWebGlobber);
CleanDirectories(cleanWebGlobber);
var cleanTestsGlobber = testsPath + "/**/" + configuration + "/bin";
Information("Cleaning {0}", cleanTestsGlobber);
CleanDirectories(cleanTestsGlobber);
});
Task("Restore")
.Does(() =>
{
// Restore all NuGet packages.
Information("Restoring {0}...", solutionPath);
NuGetRestore(solutionPath);
});
Task("Build")
.IsDependentOn("Clean")
.IsDependentOn("Restore")
.Does(() =>
{
// Build target web & tests.
Information("Building web {0}", projectPath);
MSBuild(projectPath, settings =>
settings.SetPlatformTarget(PlatformTarget.MSIL)
.WithProperty("TreatWarningsAsErrors","true")
.WithProperty("OutputPath", outputPath)
.WithTarget("Build")
.SetConfiguration(configuration));
Information("Building tests {0}", testsProjectPath);
MSBuild(testsProjectPath, settings =>
settings.SetPlatformTarget(PlatformTarget.MSIL)
.WithProperty("TreatWarningsAsErrors","true")
.WithProperty("ReferencePath", outputPath)
.WithProperty("OutputPath", testsOutputPath)
.WithTarget("Build")
.SetConfiguration(configuration));
});
Task("Run-Unit-Tests")
.IsDependentOn("Build")
.Does(() =>
{
XUnit2(testsOutputPath + "/**/*.Tests.dll", new XUnit2Settings {
NoAppDomain = true
});
});
Task("Publish")
.IsDependentOn("Run-Unit-Tests")
.Does(() =>
{
Information("Deploying web from {0} to {1}", websitePublishPath, deploymentPath);
Kudu.Sync(websitePublishPath);
});
Task("Default")
.IsDependentOn("Publish");
///////////////////////////////////////////////////////////////////////////////
// EXECUTION
///////////////////////////////////////////////////////////////////////////////
RunTarget(target);
In the above scenario it supports a solution with 3 different websites and the one that is published is based on an appsetting.
For .NET Core web apps the flow is similar, basically something like below:
DotNetCoreRestore
DotNetCoreBuild
DotNetCorePublish
Kudu.Sync
There's a couple of good blog posts on deploying to Azure with Cake:
http://cakebuild.net/blog/2015/10/cake-addin-kudu
https://hackernoon.com/delivering-functions-with-cake-4b269c50f817
https://daveaglick.com/posts/publishing-to-azure-using-cake-and-web-deploy
I want to get the nuget package list from some source
(https://nexus.sample.com) like that.When I try a below code
string void main(string args[])
{
Process commandProcess = new Process();
commandProcess.StartInfo.UseShellExecute = false;
commandProcess.StartInfo.FileName = #"C:\Nuget\nuget.exe"; // this is the path of curl where it is installed;
commandProcess.StartInfo.Arguments ="list -Verbose -AllVersions -Source http://nexus.sample.com/repository/nuget-hosted/";
commandProcess.StartInfo.CreateNoWindow = true;
commandProcess.StartInfo.RedirectStandardInput = true;
commandProcess.StartInfo.RedirectStandardOutput = true;
commandProcess.StartInfo.RedirectStandardError = true;
commandProcess.Start();
commandProcess.WaitForExit();
string output = commandProcess.StandardOutput.ReadToEnd();
}
the command console was not run.If I set StartInfo.RedirectStandardOutput= false.the command console was run.but I can't read the output value.Plese give any suggestion.
Instead of running the executable, why don't you just use NuGet.Core to list all packages ?
IPackageRepository repo = PackageRepositoryFactory.Default.CreateRepository("http://nexus.sample.com/repository/nuget-hosted");
foreach (IPackage p in repo.GetPackages())
{
Console.WriteLine(p.GetFullName());
}
For more infos : Play with Packages, programmatically!
i created an SSIS package and put in a server location and also a text file which is also in the same location where the .dtsx exist.Then i tried to call the SSIS package from my local machine using C# code.What the package is doing is taking data from the text file and storing in Database.I always get Failure message on package execution.Here is what i tried
Application app = new Application();
Package package = null;
try
{
string fileName = #"\\192.168.1.1\\Mypath\\file.txt";
package = app.LoadPackage(#"\\192.168.1.1\\Mypath\\Package.dtsx", null);
Variables vars = package.Variables;
vars["FileName"].Value = fileName;
DTSExecResult results = package.Execute();
}
catch (Exception ex)
{
throw ex;
}
finally
{
package.Dispose();
package = null;
}