views:

262

answers:

1

I want to unbind my sln file from TFS server and publish it on SVN is there any "easy" option to do this. It's easy to open sln and chose unbind option in Visual Studio, but does any one ever tried to automate this process? There is a solution to edit sln file using xmlpoke and deleting binding information, but is it safe?

+1  A: 

I have some samples published on the MSDN Code Gallery for the TFS 2010 SDK that illustrate how to do this with MSBuild and the MSBuild Community Tasks. Here's a snippet of MSBuild script from the WorkItemObjectModel sample's WorkItemType.csproj file:

<Import Project="$(MSBuildExtensionsPath32)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets" />
<ItemGroup>
  <SourceFiles
    Include="$(SolutionDir)**/*.*"
    Exclude="$(SolutionDir)Package/**/*.*;$(SolutionDir)**/bin/**/*.*;$(SolutionDir)**/obj/**/*.*;$(SolutionDir)**/internal.proj;$(SolutionDir)**/*.*scc;$(SolutionDir)$(SolutionName).zip">
    <Visible>False</Visible>
  </SourceFiles>
</ItemGroup>
<Target Name="AfterBuild" Condition="'$(Configuration)'=='Release'" 
        Inputs="@(SourceFiles)" Outputs="$(SolutionDir)$(SolutionName).zip">
  <Delete
    Files="$(SolutionDir)$(SolutionName).zip"
    Condition="Exists('$(SolutionDir)$(SolutionName).zip')" />
  <PropertyGroup>
    <PackageDir>$(SolutionDir)Package\</PackageDir>
  </PropertyGroup>
  <MakeDir 
    Directories="$(PackageDir)" />
  <Copy 
    SourceFiles="@(SourceFiles)" 
    DestinationFiles="$(PackageDir)%(RecursiveDir)%(Filename)%(Extension)" />
  <Delete 
    Files="$(PackageDir)**/bin/**/*.*;$(PackageDir)**/obj/**/*.*" />
  <RemoveDir 
    Directories="$(PackageDir)**/bin;$(PackageDir)**/obj" />
  <Attrib 
    Files="@(PackageFiles)" 
    ReadOnly="false" />
  <FileUpdate
    Files="$(PackageDir)$(SolutionFileName)"
    IgnoreCase="true"
    Regex="^\s+GlobalSection\(TeamFoundationVersionControl\).+\n(\s*Scc.*\n)+\s+EndGlobalSection"
    ReplacementText=" "
    Multiline="true"
    Singleline="false" />
  <ItemGroup>
    <ProjectFiles Include="$(PackageDir)**/*.*proj" />
  </ItemGroup>
  <FileUpdate 
    Files="@(ProjectFiles)" 
    Regex="&lt;Scc[A-z]+&gt;.+&lt;/Scc[A-z]+&gt;" 
    ReplacementText=" " />
  <ItemGroup>
    <PackageFiles Include="$(PackageDir)**\*.*" />
  </ItemGroup>
  <Zip 
    Files="@(PackageFiles)" 
    WorkingDirectory="$(PackageDir)" 
    ZipFileName="$(SolutionDir)$(SolutionName).zip" />
  <Delete 
    Files="@(PackageFiles)" />
  <RemoveDir 
    Directories="$(PackageDir)" />
</Target>

In a nutshell, this script copies the source files to a temporary directory, removes the source control bindings from the solution and project files, then zips up the sources and finally deletes the temporary directory.

Jim Lamb