diff --git a/build/_k-generate-projects.shade b/build/_k-generate-projects.shade index 50791c7109..a25be3ef43 100644 --- a/build/_k-generate-projects.shade +++ b/build/_k-generate-projects.shade @@ -22,6 +22,7 @@ skipNet45='false' */} +content var='web' include href='web.txt' content var='net45' include href='net45.txt' content var='k10' include href='k10.txt' @@ -32,7 +33,8 @@ default skipNet45='${false}' var templates = new Dictionary { { "net45", net45 }, - { "k10", k10 } + { "k10", k10 }, + { "web", web } }; if(skipNet45) @@ -213,6 +215,8 @@ functions {1}.{2}.resources "; + const string contentTemplate = @""; + // Build the list of resx files var resxFileNames = FindFilesOfType(projectDir, "*.resx"); var resxDesignerFiles = new HashSet(resxFileNames.Select(f => Path.ChangeExtension(f, "Designer.cs")), @@ -229,10 +233,23 @@ functions .Select(p => resxDesignerFiles.Contains(p) ? String.Format(resxDesignerTemplate, p, Path.GetFileNameWithoutExtension(p).Replace(".Designer", "")) : String.Format(csTemplate, p))); + + var contentFileExtensions = new [] { + "*.cshtml", + "*.css", + "*.js", + "*.html" + }; + + var contentFiles = String.Join(Environment.NewLine, + contentFileExtensions.SelectMany(ext => FindFilesOfType(projectDir, ext)) + .Select(p => String.Format(contentTemplate, p))); bool isSample = Path.GetDirectoryName(projectDir) .TrimEnd(Path.DirectorySeparatorChar) .EndsWith("samples"); + + bool isWebSample = isSample && projectName.EndsWith("Web", StringComparison.OrdinalIgnoreCase); Log("Processing sample project '{0}'", projectName); @@ -260,10 +277,12 @@ functions foreach (var pair in configs) { - var targetFramework = pair.Key; - + var targetFramework = pair.Key; + + var templateKey = isWebSample ? "web" : targetFramework; + string projectTemplate; - if(!templates.TryGetValue(targetFramework, out projectTemplate)) + if(!templates.TryGetValue(templateKey, out projectTemplate)) { Warn("Skipping project generation for " + projectName + " - " + targetFramework); continue; @@ -280,7 +299,25 @@ functions bool allowUnsafeCode = unsafeValue == null ? sharedAllowUnsafeCode : (bool)specificUnsafeValue; string extraProperties = (allowUnsafeCode ? "\ntrue" : ""); - if (isSample) + + if (isWebSample) + { + var config = Path.Combine(projectDir, "web.config"); + if(!File.Exists(config)) + { + File.WriteAllText(config, @" + + + + + + + + +"); + } + } + else if (isSample) { extraProperties += GenerateStartupAction(projectDir, projectName, packagesDir, pair.Key); } @@ -322,7 +359,7 @@ functions .Replace("{Name}", projectName) .Replace("{Defines}", String.Join(";", defines)) .Replace("{ExtraProperties}", extraProperties) - .Replace("{Files}", String.Join(Environment.NewLine, csFiles, resxFiles)) + .Replace("{Files}", String.Join(Environment.NewLine, csFiles, resxFiles, contentFiles)) .Replace("{ProjectReferences}", BuildProjectReferences(projectReferences, targetFramework, projectMapping)) .Replace("{References}", BuildReferences(allPackageReferences, gacReferences, packagesDir, targetFramework, GetCandidates(targetFramework))); @@ -331,6 +368,14 @@ functions template = template.Replace("{CSharpTargetsPath}", GetProjectKTargets(packagesDir)); } + if(isWebSample) + { + template = template.Replace("{Port}", (58189 + (projectName.GetHashCode() % 50)).ToString()) + .Replace("{TargetFramwork}", targetFramework.ToUpper()) + .Replace("{BinPath}", Path.Combine(projectDir, "bin")) + .Replace("{AspNetLoaderPath}", GetLoaderPath(packagesDir)); + } + string output = Path.Combine(projectDir, GetProjectFileName(projectName, targetFramework)); string current = ""; @@ -363,6 +408,21 @@ functions .Where(p => !p.StartsWith(@"obj\")); } + private static string GetLoaderPath(string packagesDir) + { + var interopPackage = Directory.GetDirectories(packagesDir, "Microsoft.AspNet.Loader.IIS.Interop*") + .OrderByDescending(d => d) + .FirstOrDefault(); + + if (interopPackage == null) + { + Warn("Unable to locate AspNet.Loader.dll"); + return null; + } + + return Path.Combine(interopPackage, "tools", "AspNet.Loader.dll"); + } + private static string GenerateStartupAction(string projectRoot, string projectName, string packagesDir, string configType) { // packages\ProjectK.*\tools\bin\x86\klr.exe  @@ -516,6 +576,12 @@ functions Log(reference.Key + " = " + version + " ==> " + packageDir); var libPath = Path.Combine(packageDir, "lib"); + + if(!Directory.Exists(libPath)) + { + Log(reference.Key + " = " + version + " has no lib folder"); + continue; + } var candidate = candidates.Select(c => Path.Combine(libPath, c)) diff --git a/build/web.txt b/build/web.txt new file mode 100644 index 0000000000..131cdae64c --- /dev/null +++ b/build/web.txt @@ -0,0 +1,100 @@ + + + + + Debug + AnyCPU + + + 2.0 + {{ProjectGuid}} + {349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} + Library + Properties + {Name} + {Name} + v4.5 + true + + + + + + + true + full + false + obj\_\{TargetFramwork} + DEBUG;TRACE;{TargetFramwork};{Defines} + prompt + 4 + + + pdbonly + true + obj\_\{TargetFramwork} + TRACE;{TargetFramwork};{Defines} + prompt + 4{ExtraProperties} + + + + + + + {References} + + + {Files} + + + + {ProjectReferences} + + + + Web.config + + + Web.config + + + + + + + 10.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + + + + + + True + True + {Port} + / + http://localhost:{Port}/ + False + False + + + False + + + + + + + + + \ No newline at end of file