+ // Website project methods
+
+ void AddWebsiteProperties (Project p, Dictionary<Guid, ProjectInfo> websiteProjectInfos,
+ Dictionary<Guid, ProjectInfo> projectInfos)
+ {
+ var propertyGroupByConfig = new Dictionary<string, BuildPropertyGroup> ();
+ foreach (KeyValuePair<Guid, ProjectInfo> infoPair in websiteProjectInfos) {
+ ProjectInfo info = infoPair.Value;
+ string projectGuid = infoPair.Key.ToString ();
+
+ ProjectSection section;
+ if (!info.ProjectSections.TryGetValue ("WebsiteProperties", out section)) {
+ RaiseWarning (0, String.Format ("Website project '{0}' does not have the required project section: WebsiteProperties. Ignoring project.", info.Name));
+ return;
+ }
+
+ //parse project references
+ string [] ref_guids = null;
+ string references;
+ if (section.Properties.TryGetValue ("ProjectReferences", out references)) {
+ ref_guids = references.Split (new char [] {';'}, StringSplitOptions.RemoveEmptyEntries);
+ for (int i = 0; i < ref_guids.Length; i ++) {
+ // "{guid}|foo.dll"
+ ref_guids [i] = ref_guids [i].Split ('|') [0];
+
+ Guid r_guid = new Guid (ref_guids [i]);
+ ProjectInfo ref_info;
+ if (projectInfos.TryGetValue (r_guid, out ref_info))
+ // ignore if not found
+ info.Dependencies [r_guid] = ref_info;
+ }
+ }
+
+ foreach (KeyValuePair<string, string> pair in section.Properties) {
+ //looking for -- ConfigName.AspNetCompiler.PropName
+ string [] parts = pair.Key.Split ('.');
+ if (parts.Length != 3 || String.Compare (parts [1], "AspNetCompiler") != 0)
+ continue;
+
+ string config = parts [0];
+ string propertyName = parts [2];
+
+ BuildPropertyGroup bpg;
+ if (!propertyGroupByConfig.TryGetValue (config, out bpg)) {
+ bpg = p.AddNewPropertyGroup (true);
+ bpg.Condition = String.Format (" '$(AspNetConfiguration)' == '{0}' ", config);
+ propertyGroupByConfig [config] = bpg;
+ }
+
+ bpg.AddNewProperty (String.Format ("Project_{0}_AspNet{1}", projectGuid, propertyName),
+ pair.Value);
+
+ if (!info.AspNetConfigurations.Contains (config))
+ info.AspNetConfigurations.Add (config);
+ }
+ }
+ }
+
+ // For WebSite projects
+ // The main "Build" target:
+ // 1. builds all non-website projects
+ // 2. calls target for website project
+ // - gets target path for the referenced projects
+ // - Resolves dependencies, satellites etc for the
+ // referenced project assemblies, and copies them
+ // to bin/ folder
+ void AddWebsiteTargets (Project p, Dictionary<Guid, ProjectInfo> websiteProjectInfos,
+ Dictionary<Guid, ProjectInfo> projectInfos, List<ProjectInfo>[] infosByLevel,
+ List<TargetInfo> solutionTargets)
+ {
+ foreach (ProjectInfo w_info in websiteProjectInfos.Values) {
+ // gets a linear list of dependencies
+ List<ProjectInfo> depInfos = new List<ProjectInfo> ();
+ foreach (List<ProjectInfo> pinfos in infosByLevel) {
+ foreach (ProjectInfo pinfo in pinfos)
+ if (w_info.Dependencies.ContainsKey (pinfo.Guid))
+ depInfos.Add (pinfo);
+ }
+
+ foreach (string buildTarget in new string [] {"Build", "Rebuild"})
+ AddWebsiteTarget (p, w_info, projectInfos, depInfos, solutionTargets, buildTarget);
+
+ // clean/publish are not supported for website projects
+ foreach (string buildTarget in new string [] {"Clean", "Publish"})
+ AddWebsiteUnsupportedTarget (p, w_info, depInfos, buildTarget);
+ }
+ }
+
+ void AddWebsiteTarget (Project p, ProjectInfo webProjectInfo,
+ Dictionary<Guid, ProjectInfo> projectInfos, List<ProjectInfo> depInfos,
+ List<TargetInfo> solutionTargets, string buildTarget)
+ {
+ string w_guid = webProjectInfo.Guid.ToString ().ToUpper ();
+
+ Target target = p.Targets.AddNewTarget (GetTargetNameForProject (webProjectInfo.Name, buildTarget));
+ target.Condition = "'$(CurrentSolutionConfigurationContents)' != ''";
+ target.DependsOnTargets = GetWebsiteDependsOnTarget (depInfos, buildTarget);
+
+ // this item collects all the references
+ string final_ref_item = String.Format ("Project_{0}_References{1}", w_guid,
+ buildTarget != "Build" ? "_" + buildTarget : String.Empty);
+
+ foreach (TargetInfo targetInfo in solutionTargets) {
+ int ref_num = 0;
+ foreach (ProjectInfo depInfo in depInfos) {
+ TargetInfo projectTargetInfo;
+ if (!depInfo.TargetMap.TryGetValue (targetInfo, out projectTargetInfo))
+ // Ignore, no config, so no target path
+ continue;
+
+ // GetTargetPath from the referenced project
+ AddWebsiteMSBuildTaskForReference (target, depInfo, projectTargetInfo, targetInfo,
+ final_ref_item, ref_num);
+ ref_num ++;
+ }
+ }
+
+ // resolve the references
+ AddWebsiteResolveAndCopyReferencesTasks (target, webProjectInfo, final_ref_item, w_guid);
+ }
+
+ // emits the MSBuild task to GetTargetPath for the referenced project
+ void AddWebsiteMSBuildTaskForReference (Target target, ProjectInfo depInfo, TargetInfo projectTargetInfo,
+ TargetInfo solutionTargetInfo, string final_ref_item, int ref_num)
+ {
+ BuildTask task = target.AddNewTask ("MSBuild");
+ task.SetParameterValue ("Projects", depInfo.FileName);
+ task.SetParameterValue ("Targets", "GetTargetPath");
+
+ task.SetParameterValue ("Properties", string.Format ("Configuration={0}; Platform={1}; BuildingSolutionFile=true; CurrentSolutionConfigurationContents=$(CurrentSolutionConfigurationContents); SolutionDir=$(SolutionDir); SolutionExt=$(SolutionExt); SolutionFileName=$(SolutionFileName); SolutionName=$(SolutionName); SolutionPath=$(SolutionPath)", projectTargetInfo.Configuration, projectTargetInfo.Platform));
+ task.Condition = string.Format (" ('$(Configuration)' == '{0}') and ('$(Platform)' == '{1}') ", solutionTargetInfo.Configuration, solutionTargetInfo.Platform);
+
+ string ref_item = String.Format ("{0}_{1}",
+ final_ref_item, ref_num);
+
+ task.AddOutputItem ("TargetOutputs", ref_item);
+
+ task = target.AddNewTask ("CreateItem");
+ task.SetParameterValue ("Include", String.Format ("@({0})", ref_item));
+ task.SetParameterValue ("AdditionalMetadata", String.Format ("Guid={{{0}}}",
+ depInfo.Guid.ToString ().ToUpper ()));
+ task.AddOutputItem ("Include", final_ref_item);
+ }
+
+ void AddWebsiteResolveAndCopyReferencesTasks (Target target, ProjectInfo webProjectInfo,
+ string final_ref_item, string w_guid)
+ {
+ BuildTask task = target.AddNewTask ("ResolveAssemblyReference");
+ task.SetParameterValue ("Assemblies", String.Format ("@({0}->'%(FullPath)')", final_ref_item));
+ task.SetParameterValue ("TargetFrameworkDirectories", "$(TargetFrameworkPath)");
+ task.SetParameterValue ("SearchPaths", "{RawFileName};{TargetFrameworkDirectory};{GAC}");
+ task.SetParameterValue ("FindDependencies", "true");
+ task.SetParameterValue ("FindSatellites", "true");
+ task.SetParameterValue ("FindRelatedFiles", "true");
+ task.Condition = String.Format ("Exists ('%({0}.Identity)')", final_ref_item);
+
+ string copylocal_item = String.Format ("{0}_CopyLocalFiles", final_ref_item);
+ task.AddOutputItem ("CopyLocalFiles", copylocal_item);
+
+ // Copy the references
+ task = target.AddNewTask ("Copy");
+ task.SetParameterValue ("SourceFiles", String.Format ("@({0})", copylocal_item));
+ task.SetParameterValue ("DestinationFiles", String.Format (
+ "@({0}->'$(Project_{1}_AspNetPhysicalPath)\\Bin\\%(DestinationSubDirectory)%(Filename)%(Extension)')",
+ copylocal_item, w_guid));
+
+ // AspNetConfiguration, is config for the website project, useful
+ // for overriding from command line
+ StringBuilder cond = new StringBuilder ();
+ foreach (string config in webProjectInfo.AspNetConfigurations) {
+ if (cond.Length > 0)
+ cond.Append (" or ");
+ cond.AppendFormat (" ('$(AspNetConfiguration)' == '{0}') ", config);
+ }
+ task.Condition = cond.ToString ();
+
+ task = target.AddNewTask ("Message");
+ cond = new StringBuilder ();
+ foreach (string config in webProjectInfo.AspNetConfigurations) {
+ if (cond.Length > 0)
+ cond.Append (" and ");
+ cond.AppendFormat (" ('$(AspNetConfiguration)' != '{0}') ", config);
+ }
+ task.Condition = cond.ToString ();
+ task.SetParameterValue ("Text", "Skipping as the '$(AspNetConfiguration)' configuration is " +
+ "not supported by this website project.");
+ }
+
+ void AddWebsiteUnsupportedTarget (Project p, ProjectInfo webProjectInfo, List<ProjectInfo> depInfos,
+ string buildTarget)
+ {
+ Target target = p.Targets.AddNewTarget (GetTargetNameForProject (webProjectInfo.Name, buildTarget));
+ target.DependsOnTargets = GetWebsiteDependsOnTarget (depInfos, buildTarget);
+
+ BuildTask task = target.AddNewTask ("Message");
+ task.SetParameterValue ("Text", String.Format (
+ "Target '{0}' not support for website projects", buildTarget));
+ }
+
+ string GetWebsiteDependsOnTarget (List<ProjectInfo> depInfos, string buildTarget)
+ {
+ StringBuilder deps = new StringBuilder ();
+ foreach (ProjectInfo pinfo in depInfos) {
+ if (deps.Length > 0)
+ deps.Append (";");
+ deps.Append (GetTargetNameForProject (pinfo.Name, buildTarget));
+ }
+ deps.Append (";GetFrameworkPath");
+ return deps.ToString ();
+ }
+
+ void AddGetFrameworkPathTarget (Project p)
+ {
+ Target t = p.Targets.AddNewTarget ("GetFrameworkPath");
+ BuildTask task = t.AddNewTask ("GetFrameworkPath");
+ task.AddOutputProperty ("Path", "TargetFrameworkPath");
+ }
+