├── .gitattributes ├── .gitignore ├── .nuget ├── NuGet.Config ├── NuGet.exe └── NuGet.targets ├── AutoUpdate.sln ├── AutoUpdate ├── Areas │ └── Installation │ │ ├── InstallationAreaRegistration.cs │ │ ├── Scripts │ │ └── autoupdate.js │ │ └── Views │ │ ├── Shared │ │ └── _Layout.cshtml │ │ ├── Updates │ │ ├── Check.cshtml │ │ ├── InstallUpdate.cshtml │ │ └── Upgrade.cshtml │ │ └── _ViewStart.cshtml ├── AutoUpdate.0.0.3-alpha.nupkg ├── AutoUpdate.csproj ├── AutoUpdate.nuspec ├── Controllers │ └── UpdatesController.cs ├── InstallationState.cs ├── PackageIdFilter.cs ├── Properties │ └── AssemblyInfo.cs ├── WebProjectManager.cs └── packages.config ├── LICENSE ├── README.md └── build.bat /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | *.sln merge=union 7 | *.csproj merge=union 8 | *.vbproj merge=union 9 | *.fsproj merge=union 10 | *.dbproj merge=union 11 | 12 | # Standard to msysgit 13 | *.doc diff=astextplain 14 | *.DOC diff=astextplain 15 | *.docx diff=astextplain 16 | *.DOCX diff=astextplain 17 | *.dot diff=astextplain 18 | *.DOT diff=astextplain 19 | *.pdf diff=astextplain 20 | *.PDF diff=astextplain 21 | *.rtf diff=astextplain 22 | *.RTF diff=astextplain 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Build Folders (you can keep bin if you'd like, to store dlls and pdbs) 2 | [Bb]in/ 3 | [Oo]bj/ 4 | 5 | # mstest test results 6 | TestResults 7 | 8 | ## Ignore Visual Studio temporary files, build results, and 9 | ## files generated by popular Visual Studio add-ons. 10 | 11 | # User-specific files 12 | *.suo 13 | *.user 14 | *.sln.docstates 15 | 16 | # Build results 17 | [Dd]ebug/ 18 | [Rr]elease/ 19 | x64/ 20 | *_i.c 21 | *_p.c 22 | *.ilk 23 | *.meta 24 | *.obj 25 | *.pch 26 | *.pdb 27 | *.pgc 28 | *.pgd 29 | *.rsp 30 | *.sbr 31 | *.tlb 32 | *.tli 33 | *.tlh 34 | *.tmp 35 | *.log 36 | *.vspscc 37 | *.vssscc 38 | .builds 39 | 40 | # Visual C++ cache files 41 | ipch/ 42 | *.aps 43 | *.ncb 44 | *.opensdf 45 | *.sdf 46 | 47 | # Visual Studio profiler 48 | *.psess 49 | *.vsp 50 | *.vspx 51 | 52 | # Guidance Automation Toolkit 53 | *.gpState 54 | 55 | # ReSharper is a .NET coding add-in 56 | _ReSharper* 57 | 58 | # NCrunch 59 | *.ncrunch* 60 | .*crunch*.local.xml 61 | 62 | # Installshield output folder 63 | [Ee]xpress 64 | 65 | # DocProject is a documentation generator add-in 66 | DocProject/buildhelp/ 67 | DocProject/Help/*.HxT 68 | DocProject/Help/*.HxC 69 | DocProject/Help/*.hhc 70 | DocProject/Help/*.hhk 71 | DocProject/Help/*.hhp 72 | DocProject/Help/Html2 73 | DocProject/Help/html 74 | 75 | # Click-Once directory 76 | publish 77 | 78 | # Publish Web Output 79 | *.Publish.xml 80 | 81 | # NuGet Packages Directory 82 | packages 83 | 84 | # Windows Azure Build Output 85 | csx 86 | *.build.csdef 87 | 88 | # Windows Store app package directory 89 | AppPackages/ 90 | 91 | # Others 92 | [Bb]in 93 | [Oo]bj 94 | sql 95 | TestResults 96 | [Tt]est[Rr]esult* 97 | *.Cache 98 | ClientBin 99 | [Ss]tyle[Cc]op.* 100 | ~$* 101 | *.dbmdl 102 | Generated_Code #added for RIA/Silverlight projects 103 | 104 | # Backup & report files from converting an old project file to a newer 105 | # Visual Studio version. Backup files are not needed, because we have git ;-) 106 | _UpgradeReport_Files/ 107 | Backup*/ 108 | UpgradeLog*.XML 109 | 110 | # Ignore packages 111 | *.nupkg -------------------------------------------------------------------------------- /.nuget/NuGet.Config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.nuget/NuGet.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/haacked/AutoUpdate/51a4775923c4be503f4301c40349f291cf1fe700/.nuget/NuGet.exe -------------------------------------------------------------------------------- /.nuget/NuGet.targets: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | $(MSBuildProjectDirectory)\..\ 5 | 6 | 7 | false 8 | 9 | 10 | false 11 | 12 | 13 | true 14 | 15 | 16 | false 17 | 18 | 19 | 20 | 21 | 22 | 26 | 27 | 28 | 29 | 30 | $([System.IO.Path]::Combine($(SolutionDir), ".nuget")) 31 | $([System.IO.Path]::Combine($(ProjectDir), "packages.config")) 32 | 33 | 34 | 35 | 36 | $(SolutionDir).nuget 37 | packages.config 38 | 39 | 40 | 41 | 42 | $(NuGetToolsPath)\NuGet.exe 43 | @(PackageSource) 44 | 45 | "$(NuGetExePath)" 46 | mono --runtime=v4.0.30319 $(NuGetExePath) 47 | 48 | $(TargetDir.Trim('\\')) 49 | 50 | -RequireConsent 51 | -NonInteractive 52 | 53 | "$(SolutionDir) " 54 | "$(SolutionDir)" 55 | 56 | 57 | $(NuGetCommand) install "$(PackagesConfig)" -source "$(PackageSources)" $(NonInteractiveSwitch) $(RequireConsentSwitch) -solutionDir $(PaddedSolutionDir) 58 | $(NuGetCommand) pack "$(ProjectPath)" -Properties "Configuration=$(Configuration);Platform=$(Platform)" $(NonInteractiveSwitch) -OutputDirectory "$(PackageOutputDir)" -symbols 59 | 60 | 61 | 62 | RestorePackages; 63 | $(BuildDependsOn); 64 | 65 | 66 | 67 | 68 | $(BuildDependsOn); 69 | BuildPackage; 70 | 71 | 72 | 73 | 74 | 75 | 76 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 91 | 92 | 95 | 96 | 97 | 98 | 100 | 101 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 133 | 134 | 135 | 136 | -------------------------------------------------------------------------------- /AutoUpdate.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2012 4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoUpdate", "AutoUpdate\AutoUpdate.csproj", "{C8B5C41F-821C-4858-96E8-3BAAAF0B6D47}" 5 | EndProject 6 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{C0E0D6F8-8A1D-4A9D-A378-FDDE6F638F4A}" 7 | ProjectSection(SolutionItems) = preProject 8 | .nuget\NuGet.Config = .nuget\NuGet.Config 9 | .nuget\NuGet.exe = .nuget\NuGet.exe 10 | .nuget\NuGet.targets = .nuget\NuGet.targets 11 | EndProjectSection 12 | EndProject 13 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Meta", "Meta", "{125DD0A8-CDE4-4FA3-9474-1CA6FA8A49FA}" 14 | ProjectSection(SolutionItems) = preProject 15 | .gitattributes = .gitattributes 16 | build.bat = build.bat 17 | LICENSE = LICENSE 18 | README.md = README.md 19 | EndProjectSection 20 | EndProject 21 | Global 22 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 23 | Debug|Any CPU = Debug|Any CPU 24 | Release|Any CPU = Release|Any CPU 25 | EndGlobalSection 26 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 27 | {C8B5C41F-821C-4858-96E8-3BAAAF0B6D47}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 28 | {C8B5C41F-821C-4858-96E8-3BAAAF0B6D47}.Debug|Any CPU.Build.0 = Debug|Any CPU 29 | {C8B5C41F-821C-4858-96E8-3BAAAF0B6D47}.Release|Any CPU.ActiveCfg = Release|Any CPU 30 | {C8B5C41F-821C-4858-96E8-3BAAAF0B6D47}.Release|Any CPU.Build.0 = Release|Any CPU 31 | EndGlobalSection 32 | GlobalSection(SolutionProperties) = preSolution 33 | HideSolutionNode = FALSE 34 | EndGlobalSection 35 | EndGlobal 36 | -------------------------------------------------------------------------------- /AutoUpdate/Areas/Installation/InstallationAreaRegistration.cs: -------------------------------------------------------------------------------- 1 | using System.Web.Mvc; 2 | 3 | namespace AutoUpdate { 4 | public class InstallationAreaRegistration : AreaRegistration { 5 | public override string AreaName { 6 | get { 7 | return "Installation"; 8 | } 9 | } 10 | 11 | public override void RegisterArea(AreaRegistrationContext context) { 12 | context.MapRoute( 13 | "Installation_default", 14 | "Installation/{controller}/{action}/{id}", 15 | new { action = "Index", id = UrlParameter.Optional } 16 | ); 17 | 18 | // To override package id based on convention, change it here... 19 | GlobalFilters.Filters.Add(new PackageIdFilter(null /* PackageId */)); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /AutoUpdate/Areas/Installation/Scripts/autoupdate.js: -------------------------------------------------------------------------------- 1 | $(function () { 2 | $('[data-autoupdate-check-url]').each(function () { 3 | var container = $(this); 4 | var url = container.attr('data-autoupdate-check-url'); 5 | if (url != null) { 6 | $.getJSON(url, function (data) { 7 | if (data.UpdateAvailable) { 8 | var upgradeMessage = container.find('.template').tmpl(data).prependTo(container); 9 | container.find('a.update').click(function () { 10 | var upgradeUrl = container.attr('data-autoupdate-upgrade-url'); 11 | $.getJSON(upgradeUrl, function (data) { 12 | if (data.Success) { 13 | upgradeMessage.remove(); 14 | container.find('.success-template').tmpl(data).prependTo(container); 15 | } 16 | }); 17 | }); 18 | container.fadeIn(); 19 | } 20 | }); 21 | } 22 | }); 23 | }); -------------------------------------------------------------------------------- /AutoUpdate/Areas/Installation/Views/Shared/_Layout.cshtml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | @ViewBag.Title 5 | 6 | 7 | 8 | 9 | 12 | 13 | 14 | 15 |
18 | 22 | 26 |
27 | 28 |
29 | 46 | 47 |
48 | @RenderBody() 49 | 51 |
52 |
53 | 54 | 55 | -------------------------------------------------------------------------------- /AutoUpdate/Areas/Installation/Views/Updates/Check.cshtml: -------------------------------------------------------------------------------- 1 | @model AutoUpdate.InstallationState 2 | 3 | @{ 4 | ViewBag.Title = "Checking For Updates"; 5 | } 6 | 7 |

Currently Installed

8 |
9 | @Model.Installed.Id @Model.Installed.Version 10 |
11 | 12 | 13 | @if (Model.Update != null) { 14 |

Update Available

15 | 16 | 19 | } else { 20 |

No Updates Available

21 | } -------------------------------------------------------------------------------- /AutoUpdate/Areas/Installation/Views/Updates/InstallUpdate.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | ViewBag.Title = "InstallUpdate"; 3 | } 4 | 5 |

Update Installed!

6 | 7 | 8 | -------------------------------------------------------------------------------- /AutoUpdate/Areas/Installation/Views/Updates/Upgrade.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | ViewBag.Title = "InstallUpdate"; 3 | } 4 | 5 |

Update Installed!

6 | 7 | 8 | -------------------------------------------------------------------------------- /AutoUpdate/Areas/Installation/Views/_ViewStart.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | Layout = "~/Areas/Installation/Views/Shared/_Layout.cshtml"; 3 | } -------------------------------------------------------------------------------- /AutoUpdate/AutoUpdate.0.0.3-alpha.nupkg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/haacked/AutoUpdate/51a4775923c4be503f4301c40349f291cf1fe700/AutoUpdate/AutoUpdate.0.0.3-alpha.nupkg -------------------------------------------------------------------------------- /AutoUpdate/AutoUpdate.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {C8B5C41F-821C-4858-96E8-3BAAAF0B6D47} 8 | Library 9 | Properties 10 | AutoUpdate 11 | AutoUpdate 12 | v4.5 13 | 512 14 | ..\ 15 | true 16 | 17 | 18 | true 19 | full 20 | false 21 | bin\Debug\ 22 | DEBUG;TRACE 23 | prompt 24 | 4 25 | true 26 | 27 | 28 | pdbonly 29 | true 30 | bin\Release\ 31 | TRACE 32 | prompt 33 | 4 34 | 35 | 36 | 37 | True 38 | ..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll 39 | 40 | 41 | ..\packages\Microsoft.Web.Xdt.1.0.0\lib\net40\Microsoft.Web.XmlTransform.dll 42 | 43 | 44 | False 45 | ..\packages\Nuget.Core.2.7.0\lib\net40-Client\NuGet.Core.dll 46 | 47 | 48 | 49 | 50 | 51 | 52 | True 53 | ..\packages\Microsoft.AspNet.WebPages.2.0.30506.0\lib\net40\System.Web.Helpers.dll 54 | 55 | 56 | True 57 | ..\packages\Microsoft.AspNet.Mvc.4.0.30506.0\lib\net40\System.Web.Mvc.dll 58 | 59 | 60 | True 61 | ..\packages\Microsoft.AspNet.Razor.2.0.30506.0\lib\net40\System.Web.Razor.dll 62 | 63 | 64 | True 65 | ..\packages\Microsoft.AspNet.WebPages.2.0.30506.0\lib\net40\System.Web.WebPages.dll 66 | 67 | 68 | True 69 | ..\packages\AutoUpdate.0.1.0\lib\System.Web.WebPages.Administration.dll 70 | 71 | 72 | True 73 | ..\packages\Microsoft.AspNet.WebPages.2.0.30506.0\lib\net40\System.Web.WebPages.Deployment.dll 74 | 75 | 76 | True 77 | ..\packages\Microsoft.AspNet.WebPages.2.0.30506.0\lib\net40\System.Web.WebPages.Razor.dll 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 114 | -------------------------------------------------------------------------------- /AutoUpdate/AutoUpdate.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | $id$ 5 | $version$ 6 | $title$ 7 | $author$ 8 | $author$ 9 | https://github.com/Haacked/AutoUpdate/blob/master/LICENSE 10 | https://github.com/Haacked/AutoUpdate 11 | false 12 | $description$ 13 | Fixed up the code so it actually hopefully works 14 | Copyright 2013 15 | aspnetmvc autoupdate 16 | 17 | -------------------------------------------------------------------------------- /AutoUpdate/Controllers/UpdatesController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Configuration; 3 | using System.Linq; 4 | using System.Web.Mvc; 5 | using NuGet; 6 | 7 | namespace AutoUpdate.Controllers 8 | { 9 | [Authorize] 10 | public class UpdatesController : Controller 11 | { 12 | // Methods 13 | public ActionResult Check(string packageId) 14 | { 15 | var projectManager = GetProjectManager(); 16 | var installedPackage = GetInstalledPackage(projectManager, packageId); 17 | var update = projectManager.GetUpdate(installedPackage); 18 | var model = new InstallationState 19 | { 20 | Installed = installedPackage, 21 | Update = update 22 | }; 23 | if (Request.IsAjaxRequest()) 24 | { 25 | var data = new 26 | { 27 | Version = (update != null) ? update.Version.ToString() : null, 28 | UpdateAvailable = update != null 29 | }; 30 | return Json(data, JsonRequestBehavior.AllowGet); 31 | } 32 | return View(model); 33 | } 34 | 35 | private static IPackage GetInstalledPackage(WebProjectManager projectManager, string packageId) 36 | { 37 | var package = (from p in projectManager.GetInstalledPackages(packageId) 38 | where p.Id == packageId 39 | select p).ToList().FirstOrDefault(); 40 | if (package == null) 41 | { 42 | throw new InvalidOperationException(string.Format("The package for package ID '{0}' is not installed in this website. Copy the package into the App_Data/packages folder.", packageId)); 43 | } 44 | return package; 45 | } 46 | 47 | private WebProjectManager GetProjectManager() 48 | { 49 | string remoteSource = ConfigurationManager.AppSettings["PackageSource"]; 50 | return new WebProjectManager(remoteSource, Request.MapPath("~/")); 51 | } 52 | 53 | public ActionResult Upgrade(string packageId) 54 | { 55 | var projectManager = GetProjectManager(); 56 | var installedPackage = GetInstalledPackage(projectManager, packageId); 57 | var update = projectManager.GetUpdate(installedPackage); 58 | projectManager.UpdatePackage(update); 59 | if (Request.IsAjaxRequest()) 60 | { 61 | return Json(new { Success = true, Version = update.Version.ToString() }, JsonRequestBehavior.AllowGet); 62 | } 63 | return View(update); 64 | } 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /AutoUpdate/InstallationState.cs: -------------------------------------------------------------------------------- 1 | using NuGet; 2 | 3 | namespace AutoUpdate 4 | { 5 | public class InstallationState 6 | { 7 | public IPackage Installed { get; set; } 8 | 9 | public IPackage Update { get; set; } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /AutoUpdate/PackageIdFilter.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | using System.Web.Hosting; 3 | using System.Web.Mvc; 4 | using System.Web.Routing; 5 | 6 | namespace AutoUpdate 7 | { 8 | public class PackageIdFilter : IActionFilter 9 | { 10 | // Methods 11 | public PackageIdFilter(string packageId) 12 | { 13 | this.PackageId = packageId; 14 | } 15 | 16 | private string GetPackageId(RequestContext context) 17 | { 18 | string name = context.RouteData.DataTokens["PackageId"] as string; 19 | if (name == null) 20 | { 21 | name = new DirectoryInfo(HostingEnvironment.ApplicationPhysicalPath).Name; 22 | } 23 | return name; 24 | } 25 | 26 | public void OnActionExecuted(ActionExecutedContext filterContext) 27 | { 28 | } 29 | 30 | public void OnActionExecuting(ActionExecutingContext filterContext) 31 | { 32 | if (this.PackageId == null) 33 | { 34 | this.PackageId = this.GetPackageId(filterContext.RequestContext); 35 | } 36 | filterContext.ActionParameters["PackageId"] = this.PackageId; 37 | } 38 | 39 | // Properties 40 | public string PackageId { get; private set; } 41 | } 42 | 43 | 44 | 45 | } -------------------------------------------------------------------------------- /AutoUpdate/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | // General Information about an assembly is controlled through the following 5 | // set of attributes. Change these attribute values to modify the information 6 | // associated with an assembly. 7 | [assembly: AssemblyTitle("AutoUpdate")] 8 | [assembly: AssemblyDescription("A package that helps to build self-updating web applications using NuGet.")] 9 | [assembly: AssemblyConfiguration("")] 10 | [assembly: AssemblyCompany("Phil Haack")] 11 | [assembly: AssemblyProduct("AutoUpdate")] 12 | [assembly: AssemblyCopyright("Copyright © Phil Haack 2013")] 13 | [assembly: AssemblyCulture("")] 14 | 15 | // Setting ComVisible to false makes the types in this assembly not visible 16 | // to COM components. If you need to access a type in this assembly from 17 | // COM, set the ComVisible attribute to true on that type. 18 | [assembly: ComVisible(false)] 19 | 20 | // The following GUID is for the ID of the typelib if this project is exposed to COM 21 | [assembly: Guid("9976df45-898a-4936-bdc2-262ea8ac5b54")] 22 | 23 | [assembly: AssemblyVersion(AssemblyConstants.AssemblyVersion)] 24 | [assembly: AssemblyFileVersion(AssemblyConstants.AssemblyVersion)] 25 | [assembly: AssemblyInformationalVersion(AssemblyConstants.PackageVersion)] 26 | 27 | internal static class AssemblyConstants 28 | { 29 | internal const string AssemblyVersion = PackageVersion + ".0"; 30 | internal const string PackageVersion = "0.3.0"; 31 | internal const string PrereleaseVersion = ""; // Until we ship 1.0, this isn't necessary. 32 | } -------------------------------------------------------------------------------- /AutoUpdate/WebProjectManager.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Globalization; 4 | using System.IO; 5 | using System.Linq; 6 | using System.Runtime.Versioning; 7 | using System.Web.WebPages.Administration.PackageManager; 8 | using NuGet; 9 | 10 | namespace AutoUpdate 11 | { 12 | internal class WebProjectManager 13 | { 14 | // Fields 15 | private readonly IProjectManager _projectManager; 16 | 17 | // Methods 18 | public WebProjectManager(string remoteSource, string siteRoot) 19 | { 20 | string webRepositoryDirectory = GetWebRepositoryDirectory(siteRoot); 21 | var sourceRepository = PackageRepositoryFactory.Default.CreateRepository(remoteSource); 22 | var pathResolver = new DefaultPackagePathResolver(webRepositoryDirectory); 23 | var localRepository = PackageRepositoryFactory.Default.CreateRepository(webRepositoryDirectory); 24 | IProjectSystem project = new WebProjectSystem(siteRoot); 25 | _projectManager = new ProjectManager(sourceRepository, pathResolver, project, localRepository); 26 | } 27 | 28 | public IQueryable GetInstalledPackages(string searchTerms) 29 | { 30 | return GetPackages(LocalRepository, searchTerms); 31 | } 32 | 33 | private static IEnumerable GetPackageDependencies(IPackage package, IPackageRepository localRepository, IPackageRepository sourceRepository) 34 | { 35 | var walker = new InstallWalker( 36 | localRepository, 37 | sourceRepository, 38 | new FrameworkName(".NET Framework, Version=4.0"), 39 | NullLogger.Instance, 40 | ignoreDependencies: false, 41 | allowPrereleaseVersions: true); 42 | return (from operation in walker.ResolveOperations(package) 43 | where operation.Action == PackageAction.Install 44 | select operation.Package); 45 | } 46 | 47 | internal static IQueryable GetPackages(IPackageRepository repository, string searchTerm) 48 | { 49 | return GetPackages(repository.GetPackages(), searchTerm); 50 | } 51 | 52 | internal static IQueryable GetPackages(IQueryable packages, string searchTerm) 53 | { 54 | if (!string.IsNullOrEmpty(searchTerm)) 55 | { 56 | searchTerm = searchTerm.Trim(); 57 | packages = packages.Find(searchTerm); 58 | } 59 | return packages; 60 | } 61 | 62 | internal IEnumerable GetPackagesRequiringLicenseAcceptance(IPackage package) 63 | { 64 | IPackageRepository localRepository = LocalRepository; 65 | IPackageRepository sourceRepository = SourceRepository; 66 | return GetPackagesRequiringLicenseAcceptance(package, localRepository, sourceRepository); 67 | } 68 | 69 | internal static IEnumerable GetPackagesRequiringLicenseAcceptance(IPackage package, IPackageRepository localRepository, IPackageRepository sourceRepository) 70 | { 71 | return (from p in GetPackageDependencies(package, localRepository, sourceRepository) 72 | where p.RequireLicenseAcceptance 73 | select p); 74 | } 75 | 76 | public IQueryable GetPackagesWithUpdates(string searchTerms) 77 | { 78 | return GetPackages(LocalRepository.GetUpdates( 79 | SourceRepository.GetPackages(), 80 | includePrerelease: true, 81 | includeAllVersions: true) 82 | .AsQueryable(), searchTerms); 83 | } 84 | 85 | public IQueryable GetRemotePackages(string searchTerms) 86 | { 87 | return GetPackages(SourceRepository, searchTerms); 88 | } 89 | 90 | public IPackage GetUpdate(IPackage package) 91 | { 92 | return SourceRepository.GetUpdates( 93 | LocalRepository.GetPackages(), 94 | includePrerelease: true, 95 | includeAllVersions: true) 96 | .FirstOrDefault(p => (package.Id == p.Id)); 97 | } 98 | 99 | internal static string GetWebRepositoryDirectory(string siteRoot) 100 | { 101 | return Path.Combine(siteRoot, "App_Data", "packages"); 102 | } 103 | 104 | public IEnumerable InstallPackage(IPackage package) 105 | { 106 | return PerformLoggedAction( 107 | () => _projectManager.AddPackageReference( 108 | package, 109 | ignoreDependencies: false, 110 | allowPrereleaseVersions: true)); 111 | } 112 | 113 | public bool IsPackageInstalled(IPackage package) 114 | { 115 | return LocalRepository.Exists(package); 116 | } 117 | 118 | private IEnumerable PerformLoggedAction(Action action) 119 | { 120 | var logger = new ErrorLogger(); 121 | _projectManager.Logger = logger; 122 | try 123 | { 124 | action(); 125 | } 126 | finally 127 | { 128 | _projectManager.Logger = null; 129 | } 130 | return logger.Errors; 131 | } 132 | 133 | public IEnumerable UninstallPackage(IPackage package, bool removeDependencies) 134 | { 135 | return PerformLoggedAction( 136 | () => 137 | _projectManager.RemovePackageReference(package.Id, 138 | forceRemove: false, 139 | removeDependencies: removeDependencies)); 140 | } 141 | 142 | public IEnumerable UpdatePackage(IPackage package) 143 | { 144 | return PerformLoggedAction( 145 | () => 146 | _projectManager.UpdatePackageReference( 147 | package.Id, 148 | package.Version, 149 | updateDependencies: true, 150 | allowPrereleaseVersions: true)); 151 | } 152 | 153 | // Properties 154 | public IPackageRepository LocalRepository 155 | { 156 | get 157 | { 158 | return _projectManager.LocalRepository; 159 | } 160 | } 161 | 162 | public IPackageRepository SourceRepository 163 | { 164 | get 165 | { 166 | return _projectManager.SourceRepository; 167 | } 168 | } 169 | 170 | // Nested Types 171 | private class ErrorLogger : ILogger 172 | { 173 | // Fields 174 | private readonly IList _errors = new List(); 175 | 176 | // Methods 177 | public void Log(MessageLevel level, string message, params object[] args) 178 | { 179 | if (level == MessageLevel.Warning) 180 | { 181 | _errors.Add(string.Format(CultureInfo.CurrentCulture, message, args)); 182 | } 183 | } 184 | 185 | // Properties 186 | public IEnumerable Errors 187 | { 188 | get 189 | { 190 | return _errors; 191 | } 192 | } 193 | 194 | public FileConflictResolution ResolveFileConflict(string message) 195 | { 196 | // TODO: Whatever I'm supposed to do here. 197 | throw new NotImplementedException(); 198 | } 199 | } 200 | } 201 | 202 | 203 | 204 | } -------------------------------------------------------------------------------- /AutoUpdate/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 Phil Haack 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | AutoUpdate 2 | ========== 3 | 4 | A package that helps to build self-updating web applications using NuGet. 5 | 6 | Check out the blog post [Building a Self Updating Site Using NuGet](http://haacked.com/archive/2011/01/15/building-a-self-updating-site-using-nuget.aspx) for more details about what this is all about. 7 | 8 | ## Build 9 | 10 | Run build.bat to build this solution and produce a NuGet package. 11 | -------------------------------------------------------------------------------- /build.bat: -------------------------------------------------------------------------------- 1 | @echo Off 2 | set config=%1 3 | if "%config%" == "" ( 4 | set config=Release 5 | ) 6 | if "%nuget%" == "" ( 7 | set nuget=.nuget\NuGet.exe 8 | ) 9 | 10 | 11 | %nuget% pack AutoUpdate/AutoUpdate.csproj -Build -Symbols -Prop Configuration=%config% --------------------------------------------------------------------------------