public override bool Execute() { if (!this.InputFiles.Any()) return true; Instance = new RazorGeneratorBuildTask(); if (AppConfigPath == null) { var configNames = new[] { PathUtils.CombinePaths(ProjectDir, "Web.config"), PathUtils.CombinePaths(ProjectDir, "App.config"), PathUtils.CombinePaths(ProjectDir, "web.config"), //unix PathUtils.CombinePaths(ProjectDir, "app.config"), }; AppConfigPath = configNames.FirstOrDefault(File.Exists); } // Use the task's parent project's web/app configuration file using (AppConfigScope.Change(AppConfigPath)) { var allowedConfigs = ConfigurationManager.AppSettings[ConfigurationAppKeyName] ?? this.AllowedConfigurations; // If specified, only generate source code if the Project Configuration matches the given Configuration from the user if (!ConfigurationMatches(this.ProjectConfiguration, allowedConfigs)) return true; var pageBaseTypeName = GetPageBaseTypeName(); var pathProvider = new RazorBuildPathProvider(this.ProjectDir); var transformer = new RazorViewPageTransformer(pageBaseTypeName); for (int i = 0; i < this.InputFiles.Length; i++) { var file = new RazorBuildTaskFile(this.InputFiles[i].ItemSpec, pathProvider); var pageHost = new RazorPageHost(pathProvider, file, transformer, new CSharpCodeProvider(), new Dictionary<string, string>()) { RootNamespace = this.ProjectRootNamespace }; var fileName = this.OutputFiles[i].ItemSpec = ToUniqueFilePath(this.OutputFiles[i].ItemSpec, pageHost.DefaultNamespace); var sourceCode = pageHost.GenerateSourceCode(); File.WriteAllText(fileName, sourceCode); } return true; } }
public virtual RazorPage TrackPage(IVirtualFile file) { //get the base type. var pageBaseType = this.Config.PageBaseType; var transformer = new RazorViewPageTransformer(pageBaseType); //create a RazorPage var page = new RazorPage { PageHost = new RazorPageHost(PathProvider, file, transformer, new CSharpCodeProvider(), new Dictionary<string, string>()), IsValid = false, File = file }; //add it to our pages dictionary. AddPage(page); return page; }
private RazorPageHost CreatePageHost(IVirtualFile file, RazorViewPageTransformer transformer) { return new RazorPageHost(PathProvider, file, transformer, new CSharpCodeProvider(), new Dictionary<string, string>()) { IncludeDebugInformation = IncludeDebugInformation, CompileFilter = CompileFilter, }; }
public virtual RazorPage TrackPage(Type pageType) { var pageBaseType = this.Config.PageBaseType; var transformer = new RazorViewPageTransformer(pageBaseType); var pagePath = pageType.FirstAttribute<VirtualPathAttribute>().VirtualPath.TrimStart('~'); var file = GetVirtualFile(pagePath); var page = new RazorPage { PageHost = file != null ? CreatePageHost(file, transformer) : null, PageType = pageType, IsValid = true, File = file, VirtualPath = pagePath, }; AddPage(page, pagePath); return page; }
public virtual RazorPage TrackPage(IVirtualFile file) { //get the base type. var pageBaseType = this.Config.PageBaseType; var transformer = new RazorViewPageTransformer(pageBaseType); //create a RazorPage var page = new RazorPage { PageHost = CreatePageHost(file, transformer), IsValid = false, File = file, VirtualPath = file.VirtualPath, }; //add it to our pages dictionary. AddPage(page); if (Config.PrecompilePages.GetValueOrDefault()) PrecompilePage(page); return page; }
public virtual RazorPage TrackPage(Type pageType) { var pageBaseType = this.Config.PageBaseType; var transformer = new RazorViewPageTransformer(pageBaseType); var pagePath = pageType.FirstAttribute<VirtualPathAttribute>().VirtualPath.TrimStart('~'); var file = GetVirtualFile(pagePath); var page = new RazorPage { PageHost = file != null ? new RazorPageHost(PathProvider, file, transformer, new CSharpCodeProvider(), new Dictionary<string, string>()) : null, PageType = pageType, IsValid = true, File = file, VirtualPath = pagePath, }; AddPage(page, pagePath); return page; }