Created
January 8, 2016 13:50
-
-
Save bjorkstromm/48e086efbc82d5aef9a5 to your computer and use it in GitHub Desktop.
WIP. Quick hack for migrating csproj to xproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| param( | |
| [string]$solution = ".\*.sln" | |
| ) | |
| function Get-XprojContent | |
| { | |
| param( | |
| [Guid]$guid = [Guid]::NewGuid() | |
| ) | |
| [xml]@" | |
| <?xml version="1.0" encoding="utf-8"?> | |
| <Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | |
| <PropertyGroup> | |
| <VisualStudioVersion Condition="'`$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion> | |
| <VSToolsPath Condition="'`$(VSToolsPath)' == ''">`$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v`$(VisualStudioVersion)</VSToolsPath> | |
| </PropertyGroup> | |
| <Import Project="`$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'`$(VSToolsPath)' != ''" /> | |
| <PropertyGroup Label="Globals"> | |
| <ProjectGuid>$($guid)</ProjectGuid> | |
| <RootNamespace></RootNamespace> | |
| <BaseIntermediateOutputPath Condition="'`$(BaseIntermediateOutputPath)'=='' ">..\artifacts\obj\`$(MSBuildProjectName)</BaseIntermediateOutputPath> | |
| <OutputPath Condition="'`$(OutputPath)'=='' ">..\artifacts\bin\`$(MSBuildProjectName)\</OutputPath> | |
| </PropertyGroup> | |
| <PropertyGroup> | |
| <SchemaVersion>2.0</SchemaVersion> | |
| </PropertyGroup> | |
| <Import Project="`$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'`$(VSToolsPath)' != ''" /> | |
| </Project> | |
| "@ | |
| } | |
| function Get-ProjectJsonContent | |
| { | |
| @" | |
| { | |
| "version": "1.0.0-*", | |
| "description": "", | |
| "authors": [ "" ], | |
| "tags": [ "" ], | |
| "projectUrl": "", | |
| "licenseUrl": "", | |
| "frameworks": { | |
| "net451": { }, | |
| "dotnet5.4": { | |
| "dependencies": { } | |
| } | |
| } | |
| } | |
| "@ | ConvertFrom-Json | |
| } | |
| function Get-GlobalJsonContent | |
| { | |
| @" | |
| { | |
| "projects": [ "" ], | |
| "sdk": { | |
| "version": "1.0.0-rc1-final" | |
| } | |
| } | |
| "@ | ConvertFrom-Json | |
| } | |
| $solutionFile = Get-Item $solution | |
| if($solutionFile -eq $null) | |
| { | |
| Write-Error $("Could not find file " + $solution) | |
| Exit | |
| } | |
| $solutionDir = Split-Path $solutionFile | |
| $dnxSolution = New-Object PSObject -Property @{ | |
| Path = $($solutionDir + "\" + $solutionFile.Basename + ".Dnx.sln") | |
| Content = $(Get-Content $solutionFile.FullName) | |
| } | |
| $globalJson = New-Object PSObject -Property @{ | |
| Path = $($solutionDir + "\global.json") | |
| Content = Get-GlobalJsonContent | |
| } | |
| Get-Content $solutionFile.FullName | Select-String 'Project\(' | % { | |
| $projectParts = $_ -Split '[,=]' | ForEach-Object { $_.Trim('[ "{}]') }; | |
| $project = New-Object PSObject -Property @{ | |
| Name = $projectParts[1] | |
| File = $projectParts[2] | |
| Guid = $projectParts[3] | |
| } | |
| if($project.File -match "csproj$") | |
| { | |
| Write-Host $("Migrating " + $project.Name) | |
| $csproj = (Get-Item ($solutionDir + "\" + $project.File)) | |
| $xproj = New-Object PSObject -Property @{ | |
| Path = $((Split-Path $csproj) + "\" + $csproj.Basename + ".xproj") | |
| Content = Get-XprojContent | |
| } | |
| $projectJson = New-Object PSObject -Property @{ | |
| Path = $((Split-Path $csproj) + "\project.json") | |
| Content = Get-ProjectJsonContent | |
| } | |
| $xproj.Content.Save($xproj.Path) | |
| $projectJson.Content | ConvertTo-Json -depth 999 | Out-File -Encoding "UTF8" $projectJson.Path | |
| $dnxSolution.Content = $dnxSolution.Content | | |
| % { $_ -replace $project.Guid, ($xproj.Content.Project.PropertyGroup | ? { $_.Label -eq "Globals"} | Select-Object -First 1).ProjectGuid.ToUpper() } | |
| } | |
| } | |
| $dnxSolution.Content = $dnxSolution.Content.Replace("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}","{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") | |
| $dnxSolution.Content = $dnxSolution.Content.Replace(".csproj",".xproj") | |
| $globalJson.Content | ConvertTo-Json -depth 999 | Out-File -Encoding "UTF8" $globalJson.Path | |
| $dnxSolution.Content | Out-File -Encoding "UTF8" $dnxSolution.Path |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment