3

我需要以编程方式从 sourcesafe 数据库中获取文件。知道怎么做吗?

ps:我会用C#来做。

4

3 回答 3

10
using System;
using System.Collections.Generic;
using SourceSafeTypeLib;

namespace YourNamespace
{

public class SourceSafeDatabase 
{
    private readonly string dbPath;
    private readonly string password;
    private readonly string rootProject;
    private readonly string username;
    private readonly VSSDatabaseClass vssDatabase;

    public SourceSafeDatabase(string dbPath, string username, string password, string rootProject)
    {
        this.dbPath = dbPath;
        this.username = username;
        this.password = password;
        this.rootProject = rootProject;

        vssDatabase = new VSSDatabaseClass();
    }  

    public List<string> GetAllLabels()
    {
        List<string> allLabels = new List<string>();

        VSSItem item = vssDatabase.get_VSSItem(rootProject, false);
        IVSSVersions versions = item.get_Versions(0);

        foreach (IVSSVersion version in versions)
        {
            if (version.Label.Length > 0)
            {
                allLabels.Add(version.Label);
            }
        }

        return allLabels;
    }

    public void GetLabelledVersion(string label, string project, string directory)
    {
        string outDir = directory;
        vssDatabase.get_VSSItem(rootProject, false).get_Version(label).Get(ref outDir, (int)VSSFlags.VSSFLAG_RECURSYES + (int)VSSFlags.VSSFLAG_USERRONO);
    }

    public void Open()
    {
        vssDatabase.Open(dbPath, username, password);
    }

    public void Close()
    {
        vssDatabase.Close();
    }

}


// some other code that uses it

SourceSafeDatabase sourceControlDatabase = new sourceControlDatabase(...);
sourceControlDatabase.Open();
sourceControlDatabase.GetLabelledVersion(label, rootProject, projectDirectory);
sourceControlDatabase.Close();
于 2008-11-13T10:21:11.947 回答
2

有一个命令行 SS.EXE 程序,您可以调用它来执行源代码控制操作。但是,它依赖于全局 SourceSafe 配置,因此有时很难让它做你想做的事。

于 2008-11-13T10:11:32.887 回答
2

VSS有一个OLE 库

你可能想看看这个讨论。

于 2008-11-13T10:14:56.470 回答