diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7964536 --- /dev/null +++ b/.gitignore @@ -0,0 +1,189 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.sln.docstates + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +x64/ +build/ +bld/ +[Bb]in/ +[Oo]bj/ + +# Roslyn cache directories +*.ide/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +#NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opensdf +*.sdf +*.cachefile + +# Visual Studio profiler +*.psess +*.vsp +*.vspx + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding addin-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +_NCrunch_* +.*crunch*.local.xml + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +## TODO: Comment the next line if you want to checkin your +## web deploy settings but do note that will include unencrypted +## passwords +#*.pubxml + +# NuGet Packages Directory +packages/* +## TODO: If the tool you use requires repositories.config +## uncomment the next line +#!packages/repositories.config + +# Enable "build/" folder in the NuGet Packages folder since +# NuGet packages use it for MSBuild targets. +# This line needs to be after the ignore of the build folder +# (and the packages folder if the line above has been uncommented) +!packages/build/ + +# Windows Azure Build Output +csx/ +*.build.csdef + +# Windows Store app package directory +AppPackages/ + +# Others +sql/ +*.Cache +ClientBin/ +[Ss]tyle[Cc]op.* +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.pfx +*.publishsettings +node_modules/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# LightSwitch generated files +GeneratedArtifacts/ +_Pvt_Extensions/ +ModelManifest.xml \ No newline at end of file diff --git a/Get-FileEncoding.ps1 b/Get-FileEncoding.ps1 new file mode 100644 index 0000000..ef666a6 --- /dev/null +++ b/Get-FileEncoding.ps1 @@ -0,0 +1,85 @@ +############################################################################## +## +## Get-FileEncoding +## +## From Windows PowerShell Cookbook (O'Reilly) +## by Lee Holmes (http://www.leeholmes.com/guide) +## +############################################################################## +function Get-FileEncoding { + <# + + .SYNOPSIS + + Gets the encoding of a file + + .EXAMPLE + + Get-FileEncoding.ps1 .\UnicodeScript.ps1 + + BodyName : unicodeFFFE + EncodingName : Unicode (Big-Endian) + HeaderName : unicodeFFFE + WebName : unicodeFFFE + WindowsCodePage : 1200 + IsBrowserDisplay : False + IsBrowserSave : False + IsMailNewsDisplay : False + IsMailNewsSave : False + IsSingleByte : False + EncoderFallback : System.Text.EncoderReplacementFallback + DecoderFallback : System.Text.DecoderReplacementFallback + IsReadOnly : True + CodePage : 1201 + + #> + [CmdletBinding()] + param( + ## The path of the file to get the encoding of. + $Path + ) + + Set-StrictMode -Version Latest + + ## The hashtable used to store our mapping of encoding bytes to their + ## name. For example, "255-254 = Unicode" + $encodings = @{} + + ## Find all of the encodings understood by the .NET Framework. For each, + ## determine the bytes at the start of the file (the preamble) that the .NET + ## Framework uses to identify that encoding. + $encodingMembers = [System.Text.Encoding] | + Get-Member -Static -MemberType Property + + $encodingMembers | Foreach-Object { + $encodingBytes = [System.Text.Encoding]::($_.Name).GetPreamble() -join '-' + $encodings[$encodingBytes] = $_.Name + } + + ## Find out the lengths of all of the preambles. + $encodingLengths = $encodings.Keys | Where-Object { $_ } | + Foreach-Object { ($_ -split "-").Count } + + ## Assume the encoding is UTF7 by default + $result = "UTF7" + + ## Go through each of the possible preamble lengths, read that many + ## bytes from the file, and then see if it matches one of the encodings + ## we know about. + foreach($encodingLength in $encodingLengths | Sort -Descending) + { + $bytes = (Get-Content -encoding byte -readcount $encodingLength $path)[0] + $encoding = $encodings[$bytes -join '-'] + + ## If we found an encoding that had the same preamble bytes, + ## save that output and break. + if($encoding) + { + $result = $encoding + break + } + } + + ## Finally, output the encoding. + Return [System.Text.Encoding]::$result +} \ No newline at end of file diff --git a/README.md b/README.md index ef927dc..3e9af51 100644 --- a/README.md +++ b/README.md @@ -6,10 +6,15 @@ In short, it reverses "Enable Nuget Package Restore", allowing the newer package In Visual Studio 2013, automatic package restore became part of the IDE (and the TFS build process). This method is more reliable than the older, msbuild integrated package restore. It does not require you to have nuget.exe checked in to each solution and does not require any additional msbuild targets. However, if you have the files related to the old package restore method in your project, Visual Studio will skip automatic package restore. (This behavior is likely to change soon, hopefully it does). -You can use this script to remove nuget.exe, nuget.targets, and all project and solution references to nuget.targets so you can take advantage of Automatic Package Restore. It more or less automates the process described [here](http://docs.nuget.org/docs/workflows/migrating-to-automatic-package-restore). +Use this script to remove nuget.exe, nuget.targets, and all project and solution references to nuget.targets so you can take advantage of Automatic Package Restore. It more or less automates the process described [here](http://docs.nuget.org/docs/workflows/migrating-to-automatic-package-restore). It will recurse through the directory you run the script from and do it to any solutions that may be in there somewhere. Be careful and have fun! (not responsible for anything that breaks) +# Usage +Copy this script and Get-FileEncoding.ps1 to the solution directory and run migrateToAutomaticPackageRestore.ps1. + +To also remove the property that may have been added, pass `-RemoveSolutionDirProperty` as a parameter. + ## FixHintPaths.ps1 There are some intersting scenarios where you might end up with troubles related to incorrect hintpaths in the project files which reference nuget packages that were installed while the project was loaded as part of a different solution. You might see something like `C:\Users\SomeOtherUserName\My Documents\...` or `..\..\SomeOtherSolution\packages\...` . This could be caused by a bug in nuget, or more likely, a strange organization of your folder structure. This script is a quick fix for those situations. It replaces the incorrect paths with a reference to the `$(SolutionDir)\packages`, which is almost always where Automatic Package Restore puts restored packages. If you find yourself needing this script often, it may be a smell indicating that you may have problems with how your source code is organized. diff --git a/Test/ConsoleApplication/.nuget/NuGet.Config b/Test/ConsoleApplication/.nuget/NuGet.Config new file mode 100644 index 0000000..67f8ea0 --- /dev/null +++ b/Test/ConsoleApplication/.nuget/NuGet.Config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Test/ConsoleApplication/.nuget/NuGet.exe b/Test/ConsoleApplication/.nuget/NuGet.exe new file mode 100644 index 0000000..9f8781d Binary files /dev/null and b/Test/ConsoleApplication/.nuget/NuGet.exe differ diff --git a/Test/ConsoleApplication/.nuget/NuGet.targets b/Test/ConsoleApplication/.nuget/NuGet.targets new file mode 100644 index 0000000..3f8c37b --- /dev/null +++ b/Test/ConsoleApplication/.nuget/NuGet.targets @@ -0,0 +1,144 @@ + + + + $(MSBuildProjectDirectory)\..\ + + + false + + + false + + + true + + + false + + + + + + + + + + + $([System.IO.Path]::Combine($(SolutionDir), ".nuget")) + + + + + $(SolutionDir).nuget + + + + $(MSBuildProjectDirectory)\packages.$(MSBuildProjectName.Replace(' ', '_')).config + $(MSBuildProjectDirectory)\packages.$(MSBuildProjectName).config + + + + $(MSBuildProjectDirectory)\packages.config + $(PackagesProjectConfig) + + + + + $(NuGetToolsPath)\NuGet.exe + @(PackageSource) + + "$(NuGetExePath)" + mono --runtime=v4.0.30319 "$(NuGetExePath)" + + $(TargetDir.Trim('\\')) + + -RequireConsent + -NonInteractive + + "$(SolutionDir) " + "$(SolutionDir)" + + + $(NuGetCommand) install "$(PackagesConfig)" -source "$(PackageSources)" $(NonInteractiveSwitch) $(RequireConsentSwitch) -solutionDir $(PaddedSolutionDir) + $(NuGetCommand) pack "$(ProjectPath)" -Properties "Configuration=$(Configuration);Platform=$(Platform)" $(NonInteractiveSwitch) -OutputDirectory "$(PackageOutputDir)" -symbols + + + + RestorePackages; + $(BuildDependsOn); + + + + + $(BuildDependsOn); + BuildPackage; + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Test/ConsoleApplication/App.config b/Test/ConsoleApplication/App.config new file mode 100644 index 0000000..8e15646 --- /dev/null +++ b/Test/ConsoleApplication/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Test/ConsoleApplication/ConsoleApplication.csproj b/Test/ConsoleApplication/ConsoleApplication.csproj new file mode 100644 index 0000000..7468c20 --- /dev/null +++ b/Test/ConsoleApplication/ConsoleApplication.csproj @@ -0,0 +1,59 @@ + + + + + Debug + AnyCPU + {8D914EB6-638D-40A3-9131-6586039E55D3} + Exe + Properties + ConsoleApplication + ConsoleApplication + v4.5 + 512 + ..\ + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Test/ConsoleApplication/ConsoleApplication.sln b/Test/ConsoleApplication/ConsoleApplication.sln new file mode 100644 index 0000000..4ca472d --- /dev/null +++ b/Test/ConsoleApplication/ConsoleApplication.sln @@ -0,0 +1,29 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2013 +VisualStudioVersion = 12.0.40629.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleApplication", "ConsoleApplication.csproj", "{8D914EB6-638D-40A3-9131-6586039E55D3}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{41C745F3-4BD4-4F32-BD12-9E02D5ACDE0C}" + ProjectSection(SolutionItems) = preProject + .nuget\NuGet.Config = .nuget\NuGet.Config + .nuget\NuGet.exe = .nuget\NuGet.exe + .nuget\NuGet.targets = .nuget\NuGet.targets + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {8D914EB6-638D-40A3-9131-6586039E55D3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8D914EB6-638D-40A3-9131-6586039E55D3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8D914EB6-638D-40A3-9131-6586039E55D3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8D914EB6-638D-40A3-9131-6586039E55D3}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Test/ConsoleApplication/Program.cs b/Test/ConsoleApplication/Program.cs new file mode 100644 index 0000000..6b6af10 --- /dev/null +++ b/Test/ConsoleApplication/Program.cs @@ -0,0 +1,12 @@ +namespace ConsoleApplication +{ + using System; + + public class Program + { + static void Main(string[] args) + { + Console.WriteLine("Hello World!"); + } + } +} diff --git a/Test/ConsoleApplication/Properties/AssemblyInfo.cs b/Test/ConsoleApplication/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..146b117 --- /dev/null +++ b/Test/ConsoleApplication/Properties/AssemblyInfo.cs @@ -0,0 +1,4 @@ +using System.Reflection; + +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/migrateToAutomaticPackageRestore.ps1 b/migrateToAutomaticPackageRestore.ps1 index 9b07c55..c8b49b9 100644 --- a/migrateToAutomaticPackageRestore.ps1 +++ b/migrateToAutomaticPackageRestore.ps1 @@ -1,13 +1,24 @@ +Param( + [switch]$RemoveSolutionDirProperty +) + +. (Join-Path $PSScriptRoot "Get-FileEncoding.ps1") + ######################################## # Regex Patterns for Really Bad Things! -$listOfBadStuff = @( +$listOfBadStuff = New-Object System.Collections.ArrayList +[void]$listOfBadStuff.AddRange(( #sln regex "\s*(\.nuget\\NuGet\.(exe|targets)) = \1", #*proj regexes "\s*", - "\s*(.|\n)*?" - "\s*\w*" -) + "\s*(.|\n)*?", + "\s*\w*")) + + +if ($RemoveSolutionDirProperty) { +[void]$listOfBadStuff.Add("\s*\.\.\\") +} ####################### # Delete NuGet.targets @@ -19,7 +30,7 @@ ls -Recurse -include 'NuGet.exe','NuGet.targets' | } ######################################################################################### -# Fix Project and Solution Files to reverse damage done by "Enable NuGet Package Restore +# Fix Project and Solution Files to reverse damage done by "Enable NuGet Package Restore" ls -Recurse -include *.csproj, *.sln, *.fsproj, *.vbproj, *.wixproj, *.vcxproj | foreach { @@ -29,8 +40,10 @@ ls -Recurse -include *.csproj, *.sln, *.fsproj, *.vbproj, *.wixproj, *.vcxproj | $content = $content -replace $badStuff, "" } if ($origContent -ne $content) - { - $content | out-file -encoding "UTF8" $_.FullName + { + $encoding = Get-FileEncoding $_.FullName + + [System.IO.File]::WriteAllText($_.FullName, $content, $encoding) write-host messed with $_.Name } -} +} \ No newline at end of file