Microsoft.Build.Framework specify tools version - c#

I have a target project that uses c# 6.0 I need to programatically build it.
I have the code below:
var pc = new ProjectCollection();
pc.DefaultToolsVersion = "14.0" //set tools version
var globalProperty = new Dictionary<string, string>
{
{"Configuration", "Release"},
{"Platform", "Any CPU"},
{"OutputPath", Utils.GetGaugeBinDir()}
};
var buildRequestData = new BuildRequestData(solutionFullPath, globalProperty, "14.0", new[] {"Build"}, null); //Set tools version here as well
var errorCodeAggregator = new ErrorCodeAggregator();
var buildParameters = new BuildParameters(pc) {Loggers = new ILogger[] {consoleLogger, errorCodeAggregator}};
var buildResult = BuildManager.DefaultBuildManager.Build(buildParameters, buildRequestData);
No matter where I set the tools version (of the two options above), it does not build C# 6.0.
On command line, I can do this:
msbuild foo.csproj /tv:14.0 /t:rebuild
I invoke this from MSBuild 12.0 bin directory, and it works. If I drop the /tv:14.0 flag, it fails as expected.
So, question is, what is the programatic way of specifying /tv flag to BuildManager ?

var buildRequest = new BuildRequestData(_solutionPath, globalProperties, null, new[] {"Build"},
When creating your BuildRequestData, pass null for the toolsVersion.
Then make sure the Microsoft.Build*.dll's referenced by your project are the correct version.
By default, VS will add the ones from inside it's own install directory. The updated ones should exist at "C:\Program Files (x86)\MSBuild\14.0\Bin"

Related

Selenium cannot load specific created profile in firefox driver

I am trying to get a specific firefox profile which I created beforehand.
However when i execute the below code i get an exception saying that the profile doesn't exist.
var profileManager = new FirefoxProfileManager();
var profile = profileManager.GetProfile("profile");
var options = new FirefoxOptions { Profile = profile };
profile.SetPreference("webdriver.firefox.profile", "profile");
var driver = new FirefoxDriver(#"C:\Users\danza\source\repos\InstaManager\", options);
So after investigating this problem, I found out that it was mainly a package version issue. I was using Selenium.WebDriver alpha version nuget package. The solution was to downgrade to a stable version of this nuget package.
Alternatively you can use it so
var options = new FirefoxOptions();
options.Profile = new FirefoxProfile("C:\Users\username\AppData\Roaming\Mozilla\Firefox\Profiles\profilename");
var webDriver = new FirefoxDriver(webdriverPath, options)
The firefox profiles are stored in the path AppData\Roaming\Mozilla\Firefox\Profiles

FireFox & Selenium not working on specific version

In a project, we have exact guidelines, which Selenium & FireFox Versions to run for UI Tests:
- FireFox: 33.1 (some have 33.1.1, which works also)
- NuGet Selenium.WebDriver 3.3.0
- NuGet Selenium.Support 3.3.0
The FireFoxWebDriver is initialized like this:
var firefoxDirectory = #"C:\Program Files (x86)\Mozilla Firefox\";
var driverExecutableFileName = "firefox.exe";
var profileManager = new FirefoxProfileManager();
var profile = profileManager.GetProfile("default");
profile.EnableNativeEvents = false;
profile.SetPreference("intl.accept_languages", "en-US");
profile.SetPreference("browser.download.folderList", 2);
profile.SetPreference("browser.download.dir", "C:\\Temp");
profile.SetPreference("browser.helperApps.neverAsk.saveToDisk", "text/csv,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/octet-stream");
var defaultPath = $"{firefoxDirectory}{driverExecutableFileName}";
var options = new FirefoxOptions
{
Profile = profile,
UseLegacyImplementation = true
};
var service = FirefoxDriverService.CreateDefaultService(firefoxDirectory, driverExecutableFileName);
if (File.Exists(defaultPath))
{
options.BrowserExecutableLocation = defaultPath;
}
var fireFoxDriver = new FirefoxDriver(service, options, TimeSpan.FromSeconds(30));
return fireFoxDriver;
My problem: It works on every other developer machine, but on mine, the following happens:
As soon as
var fireFoxDriver = new FirefoxDriver(service, options, TimeSpan.FromSeconds(30));
Is hit, an empty FireFox window opens, but then it stops until the Timeout is reached. The length of the timeout doesn't matter, Selenium just doesn't seem to connect.
I uninstalled FireFox, the NuGet cache etc., imported the default-profile from other developers and checked all topics regarding that problem, but most topics are related to version incompatibility, which can't be the problem, since other devs have the same environment.
Are there other known issues or possibilities, what on my machine could influence this behavior?
add this two lines to configuration
profile.SetPreference("browser.startup.homepage_override.mstone", "ignore");
profile.SetPreference("startup.homepage_welcome_url.additional", "about:blank");

Selenium.WebDriver with portable FireFox c#

I need to start Selenium with Firefox Portable.
If I start Firefox.exe portable with doublé clic, it starts.
The path to Firefox.exe is correct: A FireFoxPortable folder inside Debug project's folder.
This is the code I use:
var driverService = FirefoxDriverService.CreateDefaultService();
driverService.FirefoxBinaryPath =
Path.Combine(
AppDomain.CurrentDomain.BaseDirectory,
"FireFoxPortable",
"FireFox.exe");
driverService.HideCommandPromptWindow = true;
driverService.SuppressInitialDiagnosticInformation = true;
var options = new FirefoxOptions();
var driver = new FirefoxDriver(options);
Creating the driver I have an exception -> Cannot find Firefox binary in PATH or default install locations. Make sure Firefox is installed. OS appears to be: Vista
I try this variant, but no work:
var driver = new FirefoxDriver(driverService);
I'm using this nuget packages:
Is this the correct way?
Thanks for your time!
UPDATE ---------------------------------------------
With this code Works:
var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
"FireFoxPortable", "FireFox.exe");
FirefoxProfile profile = new FirefoxProfile();
var driver = new FirefoxDriver(new FirefoxBinary(path),profile);
But a Warning for new FirefoxDriver Shown: FirefoxDriver should not be constructed with a FirefoxBinary object. Use FirefoxOptions instead. This constructor will be removed in a future release.'
What's the correct way?

Build visual studio solution from code

I'm writing a console application to get a solution from a tfs server, build it and publish on iis, but I'm stuck at building...
I found this code, which works like a charm
public static void BuildProject()
{
string solutionPath = Path.Combine(#"C:\MySolution\Common\Common.csproj");
List<ILogger> loggers = new List<ILogger>();
loggers.Add(new ConsoleLogger());
var projectCollection = new ProjectCollection();
projectCollection.RegisterLoggers(loggers);
var project = projectCollection.LoadProject(solutionPath);
try
{
project.Build();
}
finally
{
projectCollection.UnregisterAllLoggers();
}
}
but my solution it's pretty big and contains multiple projects which depends from each other (e.g. project A has a reference to project B)
how to get the correct order to build each project?
is there a way to build the entire solution from the .sln file?
Try using the following code to load a solution and compile it:
string projectFilePath = Path.Combine(#"c:\solutions\App\app.sln");
ProjectCollection pc = new ProjectCollection();
// THERE ARE A LOT OF PROPERTIES HERE, THESE MAP TO THE MSBUILD CLI PROPERTIES
Dictionary<string, string> globalProperty = new Dictionary<string, string>();
globalProperty.Add("OutputPath", #"c:\temp");
BuildParameters bp = new BuildParameters(pc);
BuildRequestData buildRequest = new BuildRequestData(projectFilePath, globalProperty, "4.0", new string[] { "Build" }, null);
// THIS IS WHERE THE MAGIC HAPPENS - IN PROCESS MSBUILD
BuildResult buildResult = BuildManager.DefaultBuildManager.Build(bp, buildRequest);
// A SIMPLE WAY TO CHECK THE RESULT
if (buildResult.OverallResult == BuildResultCode.Success)
{
//...
}

C# TFS API "There is no working folder C:\TFS' in VS2008 installed system

I want to find out the files recently checked in using C# and TFS API from TFS2010. It works fine where MS Visual studio 2010 is installed. this is developed using VS2010, .Net 3.5.
When I use this exe in system having VS2008 installed throws error as "*There is no working folder C:\TFS"*.
This system has only 3.5 Framework.
I copied all the files from C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\ReferenceAssemblies\v2.0 along with executable.
C:\TFS is the actual mapping folder. Even tried inner folder as well.
any suggestion please. is there any way to get result from TFS without considering local mappings?
TeamFoundationServer tfsServer = new TeamFoundationServer("http://snchndevtfsapp:8080/tfs/defaultcollection");
WorkItemStore workItemStore = new WorkItemStore(tfsServer);
VersionControlServer vcServer = tfsServer.GetService(typeof(VersionControlServer)) as VersionControlServer;
var usersWorkspaces = vcServer.QueryWorkspaces(null, vcServer.AuthorizedUser, Environment.MachineName).ToList();
List<ChangedTFSItem> foundPastChanges = new System.Collections.Generic.List<ChangedTFSItem>();
var allPastChangesets = vcServer.QueryHistory(#"C:\TFS",
VersionSpec.Latest,
0,
RecursionType.Full,
null,
null,
null,
1000,
true,
false).Cast<Changeset>();
//.Where(x => x.Committer.Contains(Environment.UserName));
List<ChangedTFSItem> _foundPastChanges = allPastChangesets
.SelectMany(x => x.Changes)
.Where(x => x.Item.CheckinDate.Date >= ((DateTime)dateEdit1.EditValue))
//.DistinctBy(x => x.Item.ServerItem, x => x.Item.ServerItem.GetHashCode())
.Select(x => new ChangedTFSItem()
{
FileName = Path.GetFileName(x.Item.ServerItem),
ServerItem = usersWorkspaces[0].GetLocalItemForServerItem(x.Item.ServerItem).Replace(textEdit1.Text, ""),
LocalPath = usersWorkspaces[0].GetLocalItemForServerItem(x.Item.ServerItem),
ChangeTypeName = x.ChangeType.ToString(),
ChangeDate = x.Item.CheckinDate.ToString()
}).ToList();
Instead of placing a physical path as your first argument in Query History #"C:\TFS", try using a source control path. If are interested in all changesets, simply place the root "$/".For the task you are trying to accomplish, you can skip any local workspace connection by doing something like this:
using System;
using System.Linq;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.VersionControl.Client;
namespace GetFilesOfLatestChangesets
{
class Program
{
static void Main()
{
TfsTeamProjectCollection teamProjectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("TFS_URI"));
var vcS = teamProjectCollection.GetService(typeof (VersionControlServer)) as VersionControlServer;
var changesets =
vcS.QueryHistory("$/", VersionSpec.Latest, 0, RecursionType.Full, null, null, null, 10, true, false).
Cast<Changeset>();
foreach (var changeset in changesets)
{
Console.WriteLine("Changes for "+changeset.ChangesetId);
foreach (var change in changeset.Changes)
{
Console.WriteLine(change.Item.ServerItem);
}
}
}
}
}
but then you 'll retrieve the server paths for the changed modules and not where they have been mapped in your workstation.
One final remark: You have to QueryHistory with includeChanges = true, therefore asking for the last 1000 changesets should be rather expensive.

Categories