TFS et CSharp

De Banane Atomic
Aller à la navigationAller à la recherche
Csharp.svg
using Microsoft.TeamFoundation.Client; // assembly: Microsoft.TeamFoundation.Client

var uri = new Uri("http://mon.serveur:8080/tfs/MaCollection");
var tfsCollection = new TfsTeamProjectCollection(uri);
var tfsVersionControlServer = (VersionControlServer)tfsCollection.GetService(typeof(VersionControlServer));
var workspaceName = String.Format("Installer_{0}_{1}", Environment.UserName, Environment.MachineName);
var wsArray = tfsVersionControlServer.QueryWorkspaces("MonWorkspace", "\\" + Environment.UserName, Environment.MachineName);
if (wsArray.Length == 0)
{
    // Create the workspace
    Workspace = tfsVersionControlServer.CreateWorkspace(workspaceName, "BE\\" + Environment.UserName);
}
else
{
    // Get the workspace
    Workspace = wsArray[0];
}

// Create a mapping
var workingFolder = new WorkingFolder("$/Helios", folderName);
Workspace.CreateMapping(workingFolder);

// Get the lastest version
Workspace.Get(VersionSpec.Latest, GetOptions.Overwrite);

// Check Out
Workspace.PendEdit(@"C:\chemin\vers\mon\fichier.ext");

Checkout

Csharp.svg
using Microsoft.TeamFoundation.Client; // assembly: Microsoft.TeamFoundation.Client
using Microsoft.TeamFoundation.VersionControl.Client; // assembly: Microsoft.TeamFoundation.VersionControl.Client

public static void CheckoutFile(string fileName)
{
    var workspaceInfo = Workstation.Current.GetLocalWorkspaceInfo(fileName);
    using (var server = new TfsTeamProjectCollection(workspaceInfo.ServerUri))
    {
        var workspace = workspaceInfo.GetWorkspace(server);
        workspace.PendEdit(fileName);
    }
}

The type or namespace name 'TeamFoundation' does not exist in the namespace 'Microsoft'

Incompatibilité entre la version de la référence (4.5+) et la version du framework du projet (4.0).
Changer la version du framework du projet en 4.5+ ou changer la version de la référence en 4.0