aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Prebuild/src/Core/Targets/VS2005Target.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Prebuild/src/Core/Targets/VS2005Target.cs')
-rw-r--r--Prebuild/src/Core/Targets/VS2005Target.cs869
1 files changed, 869 insertions, 0 deletions
diff --git a/Prebuild/src/Core/Targets/VS2005Target.cs b/Prebuild/src/Core/Targets/VS2005Target.cs
new file mode 100644
index 0000000..3cfc8cd
--- /dev/null
+++ b/Prebuild/src/Core/Targets/VS2005Target.cs
@@ -0,0 +1,869 @@
1#region BSD License
2/*
3Copyright (c) 2004 Matthew Holmes (matthew@wildfiregames.com)
4
5Redistribution and use in source and binary forms, with or without modification, are permitted
6provided that the following conditions are met:
7
8* Redistributions of source code must retain the above copyright notice, this list of conditions
9 and the following disclaimer.
10* Redistributions in binary form must reproduce the above copyright notice, this list of conditions
11 and the following disclaimer in the documentation and/or other materials provided with the
12 distribution.
13* The name of the author may not be used to endorse or promote products derived from this software
14 without specific prior written permission.
15
16THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
17BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
22IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23*/
24#endregion
25
26#region CVS Information
27/*
28 * $Source$
29 * $Author: robloach $
30 * $Date: 2007-02-27 19:52:34 +0100 (ti, 27 feb 2007) $
31 * $Revision: 207 $
32 */
33#endregion
34
35using System;
36using System.Collections;
37using System.Collections.Specialized;
38using System.IO;
39
40using Prebuild.Core.Attributes;
41using Prebuild.Core.Interfaces;
42using Prebuild.Core.Nodes;
43using Prebuild.Core.Utilities;
44
45namespace Prebuild.Core.Targets
46{
47 /// <summary>
48 ///
49 /// </summary>
50 public struct ToolInfo
51 {
52 string name;
53 string guid;
54 string fileExtension;
55 string xmlTag;
56 string importProject;
57
58 /// <summary>
59 /// Gets or sets the name.
60 /// </summary>
61 /// <value>The name.</value>
62 public string Name
63 {
64 get
65 {
66 return name;
67 }
68 set
69 {
70 name = value;
71 }
72 }
73
74 /// <summary>
75 /// Gets or sets the GUID.
76 /// </summary>
77 /// <value>The GUID.</value>
78 public string Guid
79 {
80 get
81 {
82 return guid;
83 }
84 set
85 {
86 guid = value;
87 }
88 }
89
90 /// <summary>
91 /// Gets or sets the file extension.
92 /// </summary>
93 /// <value>The file extension.</value>
94 public string FileExtension
95 {
96 get
97 {
98 return fileExtension;
99 }
100 set
101 {
102 fileExtension = value;
103 }
104 }
105 /// <summary>
106 /// Gets or sets the XML tag.
107 /// </summary>
108 /// <value>The XML tag.</value>
109 public string XmlTag
110 {
111 get
112 {
113 return xmlTag;
114 }
115 set
116 {
117 xmlTag = value;
118 }
119 }
120
121 /// <summary>
122 /// Gets or sets the import project property.
123 /// </summary>
124 /// <value>The ImportProject tag.</value>
125 public string ImportProject
126 {
127 get
128 {
129 return importProject;
130 }
131 set
132 {
133 importProject = value;
134 }
135 }
136
137 /// <summary>
138 /// Initializes a new instance of the <see cref="ToolInfo"/> class.
139 /// </summary>
140 /// <param name="name">The name.</param>
141 /// <param name="guid">The GUID.</param>
142 /// <param name="fileExtension">The file extension.</param>
143 /// <param name="xml">The XML.</param>
144 /// <param name="importProject">The import project.</param>
145 public ToolInfo(string name, string guid, string fileExtension, string xml, string importProject)
146 {
147 this.name = name;
148 this.guid = guid;
149 this.fileExtension = fileExtension;
150 this.xmlTag = xml;
151 this.importProject = importProject;
152 }
153
154 /// <summary>
155 /// Initializes a new instance of the <see cref="ToolInfo"/> class.
156 /// </summary>
157 /// <param name="name">The name.</param>
158 /// <param name="guid">The GUID.</param>
159 /// <param name="fileExtension">The file extension.</param>
160 /// <param name="xml">The XML.</param>
161 public ToolInfo(string name, string guid, string fileExtension, string xml)
162 {
163 this.name = name;
164 this.guid = guid;
165 this.fileExtension = fileExtension;
166 this.xmlTag = xml;
167 this.importProject = "$(MSBuildBinPath)\\Microsoft." + xml + ".Targets";
168 }
169
170 /// <summary>
171 /// Equals operator
172 /// </summary>
173 /// <param name="obj">ToolInfo to compare</param>
174 /// <returns>true if toolInfos are equal</returns>
175 public override bool Equals(object obj)
176 {
177 if (obj == null)
178 {
179 throw new ArgumentNullException("obj");
180 }
181 if (obj.GetType() != typeof(ToolInfo))
182 return false;
183
184 ToolInfo c = (ToolInfo)obj;
185 return ((this.name == c.name) && (this.guid == c.guid) && (this.fileExtension == c.fileExtension) && (this.importProject == c.importProject));
186 }
187
188 /// <summary>
189 /// Equals operator
190 /// </summary>
191 /// <param name="c1">ToolInfo to compare</param>
192 /// <param name="c2">ToolInfo to compare</param>
193 /// <returns>True if toolInfos are equal</returns>
194 public static bool operator ==(ToolInfo c1, ToolInfo c2)
195 {
196 return ((c1.name == c2.name) && (c1.guid == c2.guid) && (c1.fileExtension == c2.fileExtension) && (c1.importProject == c2.importProject) && (c1.xmlTag == c2.xmlTag));
197 }
198
199 /// <summary>
200 /// Not equals operator
201 /// </summary>
202 /// <param name="c1">ToolInfo to compare</param>
203 /// <param name="c2">ToolInfo to compare</param>
204 /// <returns>True if toolInfos are not equal</returns>
205 public static bool operator !=(ToolInfo c1, ToolInfo c2)
206 {
207 return !(c1 == c2);
208 }
209
210 /// <summary>
211 /// Hash Code
212 /// </summary>
213 /// <returns>Hash code</returns>
214 public override int GetHashCode()
215 {
216 return name.GetHashCode() ^ guid.GetHashCode() ^ this.fileExtension.GetHashCode() ^ this.importProject.GetHashCode() ^ this.xmlTag.GetHashCode();
217
218 }
219 }
220
221 /// <summary>
222 ///
223 /// </summary>
224 [Target("vs2005")]
225 public class VS2005Target : ITarget
226 {
227 #region Inner Classes
228
229 #endregion
230
231 #region Fields
232
233 string solutionVersion = "9.00";
234 string productVersion = "8.0.50727";
235 string schemaVersion = "2.0";
236 string versionName = "Visual C# 2005";
237 VSVersion version = VSVersion.VS80;
238
239 Hashtable tools;
240 Kernel kernel;
241
242 /// <summary>
243 /// Gets or sets the solution version.
244 /// </summary>
245 /// <value>The solution version.</value>
246 protected string SolutionVersion
247 {
248 get
249 {
250 return this.solutionVersion;
251 }
252 set
253 {
254 this.solutionVersion = value;
255 }
256 }
257 /// <summary>
258 /// Gets or sets the product version.
259 /// </summary>
260 /// <value>The product version.</value>
261 protected string ProductVersion
262 {
263 get
264 {
265 return this.productVersion;
266 }
267 set
268 {
269 this.productVersion = value;
270 }
271 }
272 /// <summary>
273 /// Gets or sets the schema version.
274 /// </summary>
275 /// <value>The schema version.</value>
276 protected string SchemaVersion
277 {
278 get
279 {
280 return this.schemaVersion;
281 }
282 set
283 {
284 this.schemaVersion = value;
285 }
286 }
287 /// <summary>
288 /// Gets or sets the name of the version.
289 /// </summary>
290 /// <value>The name of the version.</value>
291 protected string VersionName
292 {
293 get
294 {
295 return this.versionName;
296 }
297 set
298 {
299 this.versionName = value;
300 }
301 }
302 /// <summary>
303 /// Gets or sets the version.
304 /// </summary>
305 /// <value>The version.</value>
306 protected VSVersion Version
307 {
308 get
309 {
310 return this.version;
311 }
312 set
313 {
314 this.version = value;
315 }
316 }
317
318 #endregion
319
320 #region Constructors
321
322 /// <summary>
323 /// Initializes a new instance of the <see cref="VS2005Target"/> class.
324 /// </summary>
325 public VS2005Target()
326 {
327 this.tools = new Hashtable();
328
329 this.tools["C#"] = new ToolInfo("C#", "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}", "csproj", "CSHARP", "$(MSBuildBinPath)\\Microsoft.CSHARP.Targets");
330 this.tools["Boo"] = new ToolInfo("Boo", "{45CEA7DC-C2ED-48A6-ACE0-E16144C02365}", "booproj", "Boo", "$(BooBinPath)\\Boo.Microsoft.Build.targets");
331 this.tools["VisualBasic"] = new ToolInfo("VisualBasic", "{F184B08F-C81C-45F6-A57F-5ABD9991F28F}", "vbproj", "VisualBasic", "$(MSBuildBinPath)\\Microsoft.VisualBasic.Targets");
332 }
333
334 #endregion
335
336 #region Private Methods
337
338 private string MakeRefPath(ProjectNode project)
339 {
340 string ret = "";
341 foreach (ReferencePathNode node in project.ReferencePaths)
342 {
343 try
344 {
345 string fullPath = Helper.ResolvePath(node.Path);
346 if (ret.Length < 1)
347 {
348 ret = fullPath;
349 }
350 else
351 {
352 ret += ";" + fullPath;
353 }
354 }
355 catch (ArgumentException)
356 {
357 this.kernel.Log.Write(LogType.Warning, "Could not resolve reference path: {0}", node.Path);
358 }
359 }
360
361 return ret;
362 }
363
364 private void WriteProject(SolutionNode solution, ProjectNode project)
365 {
366 if (!tools.ContainsKey(project.Language))
367 {
368 throw new UnknownLanguageException("Unknown .NET language: " + project.Language);
369 }
370
371 ToolInfo toolInfo = (ToolInfo)tools[project.Language];
372 string projectFile = Helper.MakeFilePath(project.FullPath, project.Name, toolInfo.FileExtension);
373 StreamWriter ps = new StreamWriter(projectFile);
374
375 kernel.CurrentWorkingDirectory.Push();
376 Helper.SetCurrentDir(Path.GetDirectoryName(projectFile));
377
378 #region Project File
379 using (ps)
380 {
381 ps.WriteLine("<Project DefaultTargets=\"Build\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">");
382 //ps.WriteLine(" <{0}", toolInfo.XMLTag);
383 ps.WriteLine(" <PropertyGroup>");
384 ps.WriteLine(" <ProjectType>Local</ProjectType>");
385 ps.WriteLine(" <ProductVersion>{0}</ProductVersion>", this.ProductVersion);
386 ps.WriteLine(" <SchemaVersion>{0}</SchemaVersion>", this.SchemaVersion);
387 ps.WriteLine(" <ProjectGuid>{{{0}}}</ProjectGuid>", project.Guid.ToString().ToUpper());
388
389 ps.WriteLine(" <Configuration Condition=\" '$(Configuration)' == '' \">Debug</Configuration>");
390 ps.WriteLine(" <Platform Condition=\" '$(Platform)' == '' \">AnyCPU</Platform>");
391 //ps.WriteLine(" <Build>");
392
393 //ps.WriteLine(" <Settings");
394 ps.WriteLine(" <ApplicationIcon>{0}</ApplicationIcon>", project.AppIcon);
395 ps.WriteLine(" <AssemblyKeyContainerName>");
396 ps.WriteLine(" </AssemblyKeyContainerName>");
397 ps.WriteLine(" <AssemblyName>{0}</AssemblyName>", project.AssemblyName);
398 foreach (ConfigurationNode conf in project.Configurations)
399 {
400 if (conf.Options.KeyFile != "")
401 {
402 ps.WriteLine(" <AssemblyOriginatorKeyFile>{0}</AssemblyOriginatorKeyFile>", conf.Options.KeyFile);
403 ps.WriteLine(" <SignAssembly>true</SignAssembly>");
404 break;
405 }
406 }
407 ps.WriteLine(" <DefaultClientScript>JScript</DefaultClientScript>");
408 ps.WriteLine(" <DefaultHTMLPageLayout>Grid</DefaultHTMLPageLayout>");
409 ps.WriteLine(" <DefaultTargetSchema>IE50</DefaultTargetSchema>");
410 ps.WriteLine(" <DelaySign>false</DelaySign>");
411
412 //if(m_Version == VSVersion.VS70)
413 // ps.WriteLine(" NoStandardLibraries = \"false\"");
414
415 ps.WriteLine(" <OutputType>{0}</OutputType>", project.Type.ToString());
416 ps.WriteLine(" <AppDesignerFolder>{0}</AppDesignerFolder>", project.DesignerFolder);
417 ps.WriteLine(" <RootNamespace>{0}</RootNamespace>", project.RootNamespace);
418 ps.WriteLine(" <StartupObject>{0}</StartupObject>", project.StartupObject);
419 //ps.WriteLine(" >");
420 ps.WriteLine(" <FileUpgradeFlags>");
421 ps.WriteLine(" </FileUpgradeFlags>");
422
423 ps.WriteLine(" </PropertyGroup>");
424
425 foreach (ConfigurationNode conf in project.Configurations)
426 {
427 ps.Write(" <PropertyGroup ");
428 ps.WriteLine("Condition=\" '$(Configuration)|$(Platform)' == '{0}|AnyCPU' \">", conf.Name);
429 ps.WriteLine(" <AllowUnsafeBlocks>{0}</AllowUnsafeBlocks>", conf.Options["AllowUnsafe"]);
430 ps.WriteLine(" <BaseAddress>{0}</BaseAddress>", conf.Options["BaseAddress"]);
431 ps.WriteLine(" <CheckForOverflowUnderflow>{0}</CheckForOverflowUnderflow>", conf.Options["CheckUnderflowOverflow"]);
432 ps.WriteLine(" <ConfigurationOverrideFile>");
433 ps.WriteLine(" </ConfigurationOverrideFile>");
434 ps.WriteLine(" <DefineConstants>{0}</DefineConstants>", conf.Options["CompilerDefines"]);
435 ps.WriteLine(" <DocumentationFile>{0}</DocumentationFile>", conf.Options["XmlDocFile"]);
436 ps.WriteLine(" <DebugSymbols>{0}</DebugSymbols>", conf.Options["DebugInformation"]);
437 ps.WriteLine(" <FileAlignment>{0}</FileAlignment>", conf.Options["FileAlignment"]);
438 // ps.WriteLine(" <IncrementalBuild = \"{0}\"", conf.Options["IncrementalBuild"]);
439
440 // if(m_Version == VSVersion.VS71)
441 // {
442 // ps.WriteLine(" NoStdLib = \"{0}\"", conf.Options["NoStdLib"]);
443 // ps.WriteLine(" NoWarn = \"{0}\"", conf.Options["SuppressWarnings"]);
444 // }
445
446 ps.WriteLine(" <Optimize>{0}</Optimize>", conf.Options["OptimizeCode"]);
447 ps.WriteLine(" <OutputPath>{0}</OutputPath>",
448 Helper.EndPath(Helper.NormalizePath(conf.Options["OutputPath"].ToString())));
449 ps.WriteLine(" <RegisterForComInterop>{0}</RegisterForComInterop>", conf.Options["RegisterComInterop"]);
450 ps.WriteLine(" <RemoveIntegerChecks>{0}</RemoveIntegerChecks>", conf.Options["RemoveIntegerChecks"]);
451 ps.WriteLine(" <TreatWarningsAsErrors>{0}</TreatWarningsAsErrors>", conf.Options["WarningsAsErrors"]);
452 ps.WriteLine(" <WarningLevel>{0}</WarningLevel>", conf.Options["WarningLevel"]);
453 ps.WriteLine(" <NoWarn>{0}</NoWarn>", conf.Options["SuppressWarnings"]);
454 ps.WriteLine(" </PropertyGroup>");
455 }
456
457 //ps.WriteLine(" </Settings>");
458
459 // Assembly References
460 ps.WriteLine(" <ItemGroup>");
461 foreach (ReferenceNode refr in project.References)
462 {
463 if (!solution.ProjectsTable.ContainsKey(refr.Name))
464 {
465 ps.Write(" <Reference");
466 ps.Write(" Include=\"");
467 ps.Write(refr.Name);
468
469 if (!string.IsNullOrEmpty(refr.Version))
470 {
471 ps.Write(", Version=");
472 ps.Write(refr.Version);
473 }
474
475 ps.WriteLine("\" >");
476
477 // TODO: Allow reference to *.exe files
478 ps.WriteLine(" <HintPath>{0}</HintPath>", Helper.MakePathRelativeTo(project.FullPath, refr.Path + "\\" + refr.Name + ".dll"));
479 ps.WriteLine(" <Private>{0}</Private>", refr.LocalCopy);
480 ps.WriteLine(" </Reference>");
481 }
482 }
483 ps.WriteLine(" </ItemGroup>");
484
485 //Project References
486 ps.WriteLine(" <ItemGroup>");
487 foreach (ReferenceNode refr in project.References)
488 {
489 if (solution.ProjectsTable.ContainsKey(refr.Name))
490 {
491 ProjectNode refProject = (ProjectNode)solution.ProjectsTable[refr.Name];
492 // TODO: Allow reference to visual basic projects
493 ps.WriteLine(" <ProjectReference Include=\"{0}\">", Helper.MakePathRelativeTo(project.FullPath, Helper.MakeFilePath(refProject.FullPath, refProject.Name, "csproj")));
494 //<ProjectReference Include="..\..\RealmForge\Utility\RealmForge.Utility.csproj">
495 ps.WriteLine(" <Name>{0}</Name>", refProject.Name);
496 // <Name>RealmForge.Utility</Name>
497 ps.WriteLine(" <Project>{{{0}}}</Project>", refProject.Guid.ToString().ToUpper());
498 // <Project>{6880D1D3-69EE-461B-B841-5319845B20D3}</Project>
499 ps.WriteLine(" <Package>{0}</Package>", toolInfo.Guid.ToString().ToUpper());
500 // <Package>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</Package>
501 ps.WriteLine("\t\t\t<Private>{0}</Private>", refr.LocalCopy);
502 ps.WriteLine(" </ProjectReference>");
503 //</ProjectReference>
504 }
505 else
506 {
507 }
508 }
509 ps.WriteLine(" </ItemGroup>");
510
511 // ps.WriteLine(" </Build>");
512 ps.WriteLine(" <ItemGroup>");
513
514 // ps.WriteLine(" <Include>");
515 ArrayList list = new ArrayList();
516 foreach (string file in project.Files)
517 {
518 // if (file == "Properties\\Bind.Designer.cs")
519 // {
520 // Console.WriteLine("Wait a minute!");
521 // Console.WriteLine(project.Files.GetSubType(file).ToString());
522 // }
523
524 if (project.Files.GetSubType(file) != SubType.Code && project.Files.GetSubType(file) != SubType.Settings && project.Files.GetSubType(file) != SubType.Designer)
525 {
526 ps.WriteLine(" <EmbeddedResource Include=\"{0}\">", file.Substring(0, file.LastIndexOf('.')) + ".resx");
527
528 int slash = file.LastIndexOf('\\');
529 if (slash == -1)
530 {
531 ps.WriteLine(" <DependentUpon>{0}</DependentUpon>", file);
532 }
533 else
534 {
535 ps.WriteLine(" <DependentUpon>{0}</DependentUpon>", file.Substring(slash + 1, file.Length - slash - 1));
536 }
537 ps.WriteLine(" <SubType>Designer</SubType>");
538 ps.WriteLine(" </EmbeddedResource>");
539 //
540 }
541
542 if (project.Files.GetSubType(file) != SubType.Code && project.Files.GetSubType(file) == SubType.Designer)
543 {
544 ps.WriteLine(" <EmbeddedResource Include=\"{0}\">", file.Substring(0, file.LastIndexOf('.')) + ".resx");
545 ps.WriteLine(" <SubType>" + project.Files.GetSubType(file) + "</SubType>");
546 ps.WriteLine(" <Generator>ResXFileCodeGenerator</Generator>");
547 ps.WriteLine(" <LastGenOutput>Resources.Designer.cs</LastGenOutput>");
548 ps.WriteLine(" </EmbeddedResource>");
549 ps.WriteLine(" <Compile Include=\"{0}\">", file.Substring(0, file.LastIndexOf('.')) + ".Designer.cs");
550 ps.WriteLine(" <AutoGen>True</AutoGen>");
551 ps.WriteLine(" <DesignTime>True</DesignTime>");
552 ps.WriteLine(" <DependentUpon>Resources.resx</DependentUpon>");
553 ps.WriteLine(" </Compile>");
554 list.Add(file.Substring(0, file.LastIndexOf('.')) + ".Designer.cs");
555 }
556 if (project.Files.GetSubType(file).ToString() == "Settings")
557 {
558 //Console.WriteLine("File: " + file);
559 //Console.WriteLine("Last index: " + file.LastIndexOf('.'));
560 //Console.WriteLine("Length: " + file.Length);
561 ps.Write(" <{0} ", project.Files.GetBuildAction(file));
562 ps.WriteLine("Include=\"{0}\">", file);
563 int slash = file.LastIndexOf('\\');
564 string fileName = file.Substring(slash + 1, file.Length - slash - 1);
565 if (project.Files.GetBuildAction(file) == BuildAction.None)
566 {
567 ps.WriteLine(" <Generator>SettingsSingleFileGenerator</Generator>");
568
569 //Console.WriteLine("FileName: " + fileName);
570 //Console.WriteLine("FileNameMain: " + fileName.Substring(0, fileName.LastIndexOf('.')));
571 //Console.WriteLine("FileNameExt: " + fileName.Substring(fileName.LastIndexOf('.'), fileName.Length - fileName.LastIndexOf('.')));
572 if (slash == -1)
573 {
574 ps.WriteLine(" <LastGenOutput>{0}</LastGenOutput>", fileName.Substring(0, fileName.LastIndexOf('.')) + ".Designer.cs");
575 }
576 else
577 {
578 ps.WriteLine(" <LastGenOutput>{0}</LastGenOutput>", fileName.Substring(0, fileName.LastIndexOf('.')) + ".Designer.cs");
579 }
580 }
581 else
582 {
583 ps.WriteLine(" <SubType>Code</SubType>");
584 ps.WriteLine(" <AutoGen>True</AutoGen>");
585 ps.WriteLine(" <DesignTimeSharedInput>True</DesignTimeSharedInput>");
586 string fileNameShort = fileName.Substring(0, fileName.LastIndexOf('.'));
587 string fileNameShorter = fileNameShort.Substring(0, fileNameShort.LastIndexOf('.'));
588 ps.WriteLine(" <DependentUpon>{0}</DependentUpon>", fileNameShorter + ".settings");
589 }
590 ps.WriteLine(" </{0}>", project.Files.GetBuildAction(file));
591 }
592 else if (project.Files.GetSubType(file) != SubType.Designer)
593 {
594 if (!list.Contains(file))
595 {
596 ps.Write(" <{0} ", project.Files.GetBuildAction(file));
597 ps.WriteLine("Include=\"{0}\">", file);
598
599
600 if (file.Contains("Designer.cs"))
601 {
602 ps.WriteLine(" <DependentUpon>{0}</DependentUpon>", file.Substring(0, file.IndexOf(".Designer.cs")) + ".cs");
603 }
604
605 if (project.Files.GetIsLink(file))
606 {
607 ps.WriteLine(" <Link>{0}</Link>", Path.GetFileName(file));
608 }
609 else if (project.Files.GetBuildAction(file) != BuildAction.None)
610 {
611 if (project.Files.GetBuildAction(file) != BuildAction.EmbeddedResource)
612 {
613 ps.WriteLine(" <SubType>{0}</SubType>", project.Files.GetSubType(file));
614 }
615 }
616 if (project.Files.GetCopyToOutput(file) != CopyToOutput.Never)
617 {
618 ps.WriteLine(" <CopyToOutputDirectory>{0}</CopyToOutputDirectory>", project.Files.GetCopyToOutput(file));
619 }
620
621 ps.WriteLine(" </{0}>", project.Files.GetBuildAction(file));
622 }
623 }
624 }
625 // ps.WriteLine(" </Include>");
626
627 ps.WriteLine(" </ItemGroup>");
628 ps.WriteLine(" <Import Project=\"" + toolInfo.ImportProject + "\" />");
629 ps.WriteLine(" <PropertyGroup>");
630 ps.WriteLine(" <PreBuildEvent>");
631 ps.WriteLine(" </PreBuildEvent>");
632 ps.WriteLine(" <PostBuildEvent>");
633 ps.WriteLine(" </PostBuildEvent>");
634 ps.WriteLine(" </PropertyGroup>");
635 // ps.WriteLine(" </{0}>", toolInfo.XMLTag);
636 ps.WriteLine("</Project>");
637 }
638 #endregion
639
640 #region User File
641
642 ps = new StreamWriter(projectFile + ".user");
643 using (ps)
644 {
645 ps.WriteLine("<Project xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">");
646 //ps.WriteLine( "<VisualStudioProject>" );
647 //ps.WriteLine(" <{0}>", toolInfo.XMLTag);
648 //ps.WriteLine(" <Build>");
649 ps.WriteLine(" <PropertyGroup>");
650 //ps.WriteLine(" <Settings ReferencePath=\"{0}\">", MakeRefPath(project));
651 ps.WriteLine(" <Configuration Condition=\" '$(Configuration)' == '' \">Debug</Configuration>");
652 ps.WriteLine(" <Platform Condition=\" '$(Platform)' == '' \">AnyCPU</Platform>");
653 ps.WriteLine(" <ReferencePath>{0}</ReferencePath>", MakeRefPath(project));
654 ps.WriteLine(" <LastOpenVersion>{0}</LastOpenVersion>", this.ProductVersion);
655 ps.WriteLine(" <ProjectView>ProjectFiles</ProjectView>");
656 ps.WriteLine(" <ProjectTrust>0</ProjectTrust>");
657 ps.WriteLine(" </PropertyGroup>");
658 foreach (ConfigurationNode conf in project.Configurations)
659 {
660 ps.Write(" <PropertyGroup");
661 ps.Write(" Condition = \" '$(Configuration)|$(Platform)' == '{0}|AnyCPU' \"", conf.Name);
662 ps.WriteLine(" />");
663 }
664 //ps.WriteLine(" </Settings>");
665
666 //ps.WriteLine(" </Build>");
667 //ps.WriteLine(" </{0}>", toolInfo.XMLTag);
668 //ps.WriteLine("</VisualStudioProject>");
669 ps.WriteLine("</Project>");
670 }
671 #endregion
672
673 kernel.CurrentWorkingDirectory.Pop();
674 }
675
676 private void WriteSolution(SolutionNode solution)
677 {
678 kernel.Log.Write("Creating {0} solution and project files", this.VersionName);
679
680 foreach (ProjectNode project in solution.Projects)
681 {
682 kernel.Log.Write("...Creating project: {0}", project.Name);
683 WriteProject(solution, project);
684 }
685
686 kernel.Log.Write("");
687 string solutionFile = Helper.MakeFilePath(solution.FullPath, solution.Name, "sln");
688 StreamWriter ss = new StreamWriter(solutionFile);
689
690 kernel.CurrentWorkingDirectory.Push();
691 Helper.SetCurrentDir(Path.GetDirectoryName(solutionFile));
692
693 using (ss)
694 {
695 ss.WriteLine("Microsoft Visual Studio Solution File, Format Version {0}", this.SolutionVersion);
696 ss.WriteLine("# Visual Studio 2005");
697 foreach (ProjectNode project in solution.Projects)
698 {
699 if (!tools.ContainsKey(project.Language))
700 {
701 throw new UnknownLanguageException("Unknown .NET language: " + project.Language);
702 }
703
704 ToolInfo toolInfo = (ToolInfo)tools[project.Language];
705
706 string path = Helper.MakePathRelativeTo(solution.FullPath, project.FullPath);
707 ss.WriteLine("Project(\"{0}\") = \"{1}\", \"{2}\", \"{{{3}}}\"",
708 toolInfo.Guid, project.Name, Helper.MakeFilePath(path, project.Name,
709 toolInfo.FileExtension), project.Guid.ToString().ToUpper());
710
711 //ss.WriteLine(" ProjectSection(ProjectDependencies) = postProject");
712 //ss.WriteLine(" EndProjectSection");
713
714 ss.WriteLine("EndProject");
715 }
716
717 if (solution.Files != null)
718 {
719 ss.WriteLine("Project(\"{0}\") = \"Solution Items\", \"Solution Items\", \"{1}\"", "{2150E333-8FDC-42A3-9474-1A3956D46DE8}", "{468F1D07-AD17-4CC3-ABD0-2CA268E4E1A6}");
720 ss.WriteLine("\tProjectSection(SolutionItems) = preProject");
721 foreach (string file in solution.Files)
722 ss.WriteLine("\t\t{0} = {0}", file);
723 ss.WriteLine("\tEndProjectSection");
724 ss.WriteLine("EndProject");
725 }
726
727 ss.WriteLine("Global");
728
729 ss.WriteLine(" GlobalSection(SolutionConfigurationPlatforms) = preSolution");
730 foreach (ConfigurationNode conf in solution.Configurations)
731 {
732 ss.WriteLine(" {0}|Any CPU = {0}|Any CPU", conf.Name);
733 }
734 ss.WriteLine(" EndGlobalSection");
735
736 if (solution.Projects.Count > 1)
737 {
738 ss.WriteLine(" GlobalSection(ProjectDependencies) = postSolution");
739 }
740 foreach (ProjectNode project in solution.Projects)
741 {
742 for (int i = 0; i < project.References.Count; i++)
743 {
744 ReferenceNode refr = (ReferenceNode)project.References[i];
745 if (solution.ProjectsTable.ContainsKey(refr.Name))
746 {
747 ProjectNode refProject = (ProjectNode)solution.ProjectsTable[refr.Name];
748 ss.WriteLine(" ({{{0}}}).{1} = ({{{2}}})",
749 project.Guid.ToString().ToUpper()
750 , i,
751 refProject.Guid.ToString().ToUpper()
752 );
753 }
754 }
755 }
756 if (solution.Projects.Count > 1)
757 {
758 ss.WriteLine(" EndGlobalSection");
759 }
760 ss.WriteLine(" GlobalSection(ProjectConfigurationPlatforms) = postSolution");
761 foreach (ProjectNode project in solution.Projects)
762 {
763 foreach (ConfigurationNode conf in solution.Configurations)
764 {
765 ss.WriteLine(" {{{0}}}.{1}|Any CPU.ActiveCfg = {1}|Any CPU",
766 project.Guid.ToString().ToUpper(),
767 conf.Name);
768
769 ss.WriteLine(" {{{0}}}.{1}|Any CPU.Build.0 = {1}|Any CPU",
770 project.Guid.ToString().ToUpper(),
771 conf.Name);
772 }
773 }
774 ss.WriteLine(" EndGlobalSection");
775 ss.WriteLine(" GlobalSection(SolutionProperties) = preSolution");
776 ss.WriteLine(" HideSolutionNode = FALSE");
777 ss.WriteLine(" EndGlobalSection");
778
779 ss.WriteLine("EndGlobal");
780 }
781
782 kernel.CurrentWorkingDirectory.Pop();
783 }
784
785 private void CleanProject(ProjectNode project)
786 {
787 kernel.Log.Write("...Cleaning project: {0}", project.Name);
788
789 ToolInfo toolInfo = (ToolInfo)tools[project.Language];
790 string projectFile = Helper.MakeFilePath(project.FullPath, project.Name, toolInfo.FileExtension);
791 string userFile = projectFile + ".user";
792
793 Helper.DeleteIfExists(projectFile);
794 Helper.DeleteIfExists(userFile);
795 }
796
797 private void CleanSolution(SolutionNode solution)
798 {
799 kernel.Log.Write("Cleaning {0} solution and project files", this.VersionName, solution.Name);
800
801 string slnFile = Helper.MakeFilePath(solution.FullPath, solution.Name, "sln");
802 string suoFile = Helper.MakeFilePath(solution.FullPath, solution.Name, "suo");
803
804 Helper.DeleteIfExists(slnFile);
805 Helper.DeleteIfExists(suoFile);
806
807 foreach (ProjectNode project in solution.Projects)
808 {
809 CleanProject(project);
810 }
811
812 kernel.Log.Write("");
813 }
814
815 #endregion
816
817 #region ITarget Members
818
819 /// <summary>
820 /// Writes the specified kern.
821 /// </summary>
822 /// <param name="kern">The kern.</param>
823 public virtual void Write(Kernel kern)
824 {
825 if (kern == null)
826 {
827 throw new ArgumentNullException("kern");
828 }
829 kernel = kern;
830 foreach (SolutionNode sol in kernel.Solutions)
831 {
832 WriteSolution(sol);
833 }
834 kernel = null;
835 }
836
837 /// <summary>
838 /// Cleans the specified kern.
839 /// </summary>
840 /// <param name="kern">The kern.</param>
841 public virtual void Clean(Kernel kern)
842 {
843 if (kern == null)
844 {
845 throw new ArgumentNullException("kern");
846 }
847 kernel = kern;
848 foreach (SolutionNode sol in kernel.Solutions)
849 {
850 CleanSolution(sol);
851 }
852 kernel = null;
853 }
854
855 /// <summary>
856 /// Gets the name.
857 /// </summary>
858 /// <value>The name.</value>
859 public virtual string Name
860 {
861 get
862 {
863 return "vs2005";
864 }
865 }
866
867 #endregion
868 }
869}