Programmatically Merging using TeamFoundationClient TFS2008 and VS2010 - c#

I have Addin VS (maybe in future VSIX) for VS 2010.
I want to do branch of any single files (sql files) and later do merge programmatically.
I have seen several options:
GetStatus status = workspace.Merge
How to merge TFS change sets programmatically?
http://blogs.microsoft.co.il/shair/2009/04/20/tfs-api-part-19-merge/
MergeContent(Conflict, true);
workspace.Merge can show dialog modal for merge (diffmerge.exe I think) and show results (resolveing conflicts) ? Note: in my case, now, I want show merge tool.
TFS API MergeContent returns false without showing merge tool
There are tf commands (command line, not C##
tf diff[erence] itemspec [/version:versionspec]
tf merge [/recursive] [/force] [/candidate] [/discard]
[/version:versionspec] [/lock:none|checkin|checkout] [/preview]
[/baseless] [/nosummary] [/noimplicitbaseless] [/conservative]
[/format:(brief|detailed)] [/noprompt] [/login:username,[password]]
source destination
tf resolve [itemspec]
[/auto:(AutoMerge|TakeTheirs|KeepYours|
OverwriteLocal|DeleteConflict
|KeepYoursRenameTheirs)]
[/preview] [(/overridetype:overridetype | /converttotype:converttype]
[/recursive]
[/newname:path] [/noprompt]
[/login:username, [password]]
any suggestions for do merging of files, and have to options:
1) show dialog for merging (diffmerge)
2) auto, without show dialog for merging (diffmerge or another?) and resolving conflicts.

copy vsDiffMerge.exe from visual studio installation dir C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE inside App Exe file
var mergetool = new ThirdPartyToolDefinition(".*",ToolOperations.Merge,"vsDiffMerge.exe","","/m %1 %2 %3 %4");
var toolcol= ThirdPartyToolDefinitionCollection.Instance.FindTool(".*",ToolOperations.Merge);
if (toolcol == null)
{
ThirdPartyToolDefinitionCollection.Instance.AddTool(mergetool);
ThirdPartyToolDefinitionCollection.Instance.PersistAllToRegistry();
}
var controlsAssembly = Assembly.GetAssembly(typeof(ControlAddItemsExclude));
var vcResolveCoinflictsDialogType = controlsAssembly.GetType("Microsoft.TeamFoundation.VersionControl.Controls.DialogResolveConflicts");
var ci = vcResolveCoinflictsDialogType.GetConstructor(BindingFlags.Instance | BindingFlags.Public, null, new[] { typeof(Workspace), typeof(string[]), typeof(bool) }, null);
var resolveCoinflictsDialog = (Form)ci.Invoke(new object[] { workspace, null, true });
resolveCoinflictsDialog.ShowDialog(parent);
ThirdPartyToolDefinitionCollection.Instance.Remove(mergetool);
ThirdPartyToolDefinitionCollection.Instance.PersistAllToRegistry();

Related

Could not load file or assembly "path" or one of its dependencies. The system cannot find the file specified

I have a service. I tried to install it using c#. Even though service file is present i got error message
Could not load file or assembly 'file:///C:\Sample\sample.exe' or one of its dependencies. The system cannot find the file specified.
i used installutil for installation and it succeeded.
string Path = #"C:\sample\sample.exe";
string[] commandLineOptions = new string[1] { "/LogFile=install.log" };
using (AssemblyInstaller installer = new AssemblyInstaller(Path, commandLineOptions))
{
installer.UseNewContext = true;
installer.Install(null);
installer.Commit(null);
}
this code produced error
same path with installutil succeede.
I checked path, sample.exe file was present in the specified location. why this error occurs?
Edit
first time while run this code file is not present and exception will occure. at that time i will copy file to the specified location and same code call again.
in second time actually file exists but same error message is showing.
after using AssemblyInstaller we need to unload the files.
var domain = AppDomain.CreateDomain("MyDomain");
using (AssemblyInstaller installer = domain.CreateInstance(typeof(AssemblyInstaller).Assembly.FullName, typeof(AssemblyInstaller).FullName, false, BindingFlags.Public | BindingFlags.CreateInstance | BindingFlags.Instance | BindingFlags.ExactBinding, null, new Object[] { Path, new String[] { } }, null, null, null).Unwrap() as AssemblyInstaller)
{
installer.UseNewContext = true;
installer.Install(null);
installer.Commit(null);
}
AppDomain.Unload(domain);
using a AppDomain we can unload the assembly. By this .exe file will be released after the operation

Microsoft.Build.Framework specify tools version

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"

How to "programmatically" integrate diff tool with Visual Studio

Is there a way to "programatically" integrate a diff tool (like WinDiff and WinMerge) with Visual Studio 2010? These files are not the files found at Solution Explorer.
The program would have to search and store in the List the files found from certain directory, and then compare the files with same names recursively.
As far as I can gather, you're looking for the TFS Difference class. Here's an example of how to use it:
string f1 = #"file1.cs";
string f2 = #"f2.cs";
Microsoft.TeamFoundation.VersionControl.Common.DiffOptions options = new Microsoft.TeamFoundation.VersionControl.Common.DiffOptions();
options.Recursive = true;
options.StreamWriter = new System.IO.StreamWriter(Console.OpenStandardOutput());
options.UseThirdPartyTool = true;
options.OutputType = Microsoft.TeamFoundation.VersionControl.Common.DiffOutputType.Unified;
var diff = Difference.DiffFiles(
f1, FileType.Detect(f1, null),
f2, FileType.Detect(f2, null),
options);
while (diff != null)
{
// Do whatever it is that you want to do here
diff = diff.Next;
}
You may want to take a look whether this extension is what you need: http://visualstudiogallery.msdn.microsoft.com/dace3633-0b51-4629-85d4-c59cdce5bb3b?SRC=Featured

Create designer.cs file from ResXRersourcewriter generated resource file

I got a programm that generates .resx resource files. Those resource files are used in other projects, that isnt in the same solution as the project that generates the resource files.
I wonder now, if its possible to generate a designer.cs file from the resource file, so that you can access the resources directly without using the resxresourcereader.
Open the resx file and on its toolbar there's an Access Modifier menu. Set this to Public. This will generate a *.Designer.cs file.
Right click on the Resources.resx and select "Run Custom Tool".
If the file is added to a Visual Studio Project you have to set the Custom Tool property of the .resx file to ResXFileCodeGenerator. Then will VS automatically create the needed designer file.
In one project I made a T4 script that scans the folder within the project for all images and let create a corresponding ressource file at a click.
Here is the needed part out of the T4 script:
var rootPath = Path.GetDirectoryName(this.Host.TemplateFile);
var imagesPath = Path.Combine(rootPath, "Images");
var resourcesPath = Path.Combine(rootPath, "Resources");
var pictures = Directory.GetFiles(imagesPath, "*.png", SearchOption.AllDirectories);
EnvDTE.DTE dte = (EnvDTE.DTE)((IServiceProvider)this.Host)
.GetService(typeof(EnvDTE.DTE));
EnvDTE.Projects projects = dte.Solution.Projects;
EnvDTE.Project iconProject = projects.Cast<EnvDTE.Project>().Where(p => p.Name == "Icons").Single();
EnvDTE.ProjectItem resourcesFolder = iconProject.ProjectItems.Cast<EnvDTE.ProjectItem>().Where(item => item.Name == "Resources").Single();
// Delete all existing resource files to avoid any conflicts.
foreach (var item in resourcesFolder.ProjectItems.Cast<EnvDTE.ProjectItem>())
{
item.Delete();
}
// Create the needed .resx file fore each picture.
foreach (var picture in pictures)
{
var resourceFilename = Path.GetFileNameWithoutExtension(picture) + ".resx";
var resourceFilePath = Path.Combine(resourcesPath, resourceFilename);
using (var writer = new ResXResourceWriter(resourceFilePath))
{
foreach (var picture in picturesByBitmapCollection)
{
writer.AddResource(picture.PictureName, new ResXFileRef(picture, typeof(Bitmap).AssemblyQualifiedName));
}
}
}
// Add the .resx file to the project and set the CustomTool property.
foreach (var resourceFile in Directory.GetFiles(resourcesPath, "*.resx"))
{
var createdItem = resourcesFolder.Collection.AddFromFile(resourceFile);
var allProperties = createdItem.Properties.Cast<EnvDTE.Property>().ToList();
createdItem.Properties.Item("CustomTool").Value = "ResXFileCodeGenerator";
}
I have flattened the above code a little bit, cause in my real solution i use a custom class for each picture instead of the simple filename to also support the same filename in different sub folders (by using a part of the folder structure for the namespace generation). But for a first shot the above should help you.
You can also do this in code:
(Taken from here: msdn)
StreamWriter sw = new StreamWriter(#".\DemoResources.cs");
string[] errors = null;
CSharpCodeProvider provider = new CSharpCodeProvider();
CodeCompileUnit code = StronglyTypedResourceBuilder.Create("Demo.resx", "DemoResources",
"DemoApp", provider,
false, out errors);
if (errors.Length > 0)
foreach (var error in errors)
Console.WriteLine(error);
provider.GenerateCodeFromCompileUnit(code, sw, new CodeGeneratorOptions());
sw.Close();
You need to reference system.design.dll
This also worked for me: double click and open the resx file, add a dummy resource, click save. the .designer.cs file is generated.
If you deleted it or added it to .gitignore because you thought you didn't need it. this is how you regenerate the file.
Go to the Access modifier and change it from (Public/Internal) to "No Code Generation"
Now put it back to Public/Internal.
VS will regenerate the Designer file for you.

specify build action of content - Nuget

What is the simplest way to tell Nuget package to add all css files as an embedded resource (ie build action is embedded resource).
I am trying to do it through install.ps1 in the tools folder but still cant get anywhere
Note: I am creating the package from the directory structure(tools\content\lib)
This is my install.ps1 which does not work.
param($installPath, $toolsPath, $package, $project)
$MsbNS = #{msb = 'http://schemas.microsoft.com/developer/msbuild/2003'}
function EmbeddContent($ProjectLink, [string]$XPath)
{
$nodes = #(Select-Xml $XPath $ProjectLink -Namespace $MsbNS | Foreach {$_.Node})
foreach ($node in $nodes)
{
if($node.Include.StartsWith("Content\css"))
{
$cet = $node.ownerdocument.CreateElement("EmbeddedResource")
$cet.setAttribute("Include", $node.Include)
$parent = $node.ParentNode
[void]$parent.RemoveChild($node)
[void]$parent.Appendchild($cet)
}
}
}
$project.Save()
$fileLocation = $project.FileName
$dte.ExecuteCommand("Project.UnloadProject");
$proj = [xml](gc $fileLocation)
Embeddcontent $fileLocation '//msb:Project/msb:ItemGroup/msb:Content'
$proj.Save($fileLocation)
Help Please ..
You can use DTE instead of messing with xml to change the BuildAction. From http://nuget.codeplex.com/discussions/227696:
$item = $project.ProjectItems | where-object {$_.Name -eq "ReleaseNotes.txt"}
$item.Properties.Item("BuildAction").Value = [int]3
This link shows the enumeration values:
http://msdn.microsoft.com/en-us/library/aa983962(VS.71).aspx

Categories