NETProjectGen.cpp 64 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925
  1. //
  2. // Copyright (c) 2014-2016 THUNDERBEAST GAMES LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #include <Poco/UUID.h>
  23. #include <Poco/UUIDGenerator.h>
  24. #include <Atomic/IO/Log.h>
  25. #include <Atomic/IO/File.h>
  26. #include <Atomic/IO/FileSystem.h>
  27. #include "../ToolEnvironment.h"
  28. #include "../ToolSystem.h"
  29. #include "../Project/ProjectSettings.h"
  30. #include "../Project/Project.h"
  31. #include "NETProjectGen.h"
  32. #include "NETProjectSystem.h"
  33. namespace ToolCore
  34. {
  35. NETProjectBase::NETProjectBase(Context* context, NETProjectGen* projectGen) :
  36. Object(context), xmlFile_(new XMLFile(context)), projectGen_(projectGen)
  37. {
  38. }
  39. NETProjectBase::~NETProjectBase()
  40. {
  41. }
  42. void NETProjectBase::ReplacePathStrings(String& path)
  43. {
  44. ToolEnvironment* tenv = GetSubsystem<ToolEnvironment>();
  45. String atomicRoot = tenv->GetRootSourceDir();
  46. atomicRoot = RemoveTrailingSlash(atomicRoot);
  47. path.Replace("$ATOMIC_ROOT$", atomicRoot, false);
  48. String atomicProjectPath = projectGen_->GetAtomicProjectPath();
  49. // TODO: This is the cause of a bunch of "GetSanitizedPath" calls,
  50. // It should be removed, and the few places in csproj/sln that need backslash
  51. // adjusted there
  52. atomicProjectPath.Replace("/", "\\");
  53. if (atomicProjectPath.Length())
  54. {
  55. path.Replace("$ATOMIC_PROJECT_ROOT$", atomicProjectPath, false);
  56. }
  57. }
  58. NETCSProject::NETCSProject(Context* context, NETProjectGen* projectGen) : NETProjectBase(context, projectGen),
  59. genAssemblyDocFile_(false),
  60. playerApplication_(false),
  61. androidApplication_(false)
  62. {
  63. }
  64. NETCSProject::~NETCSProject()
  65. {
  66. }
  67. bool NETCSProject::SupportsDesktop() const
  68. {
  69. if (!platforms_.Size())
  70. return true;
  71. if (platforms_.Contains("desktop") || platforms_.Contains("windows") || platforms_.Contains("macosx") || platforms_.Contains("linux"))
  72. return true;
  73. return false;
  74. }
  75. bool NETCSProject::SupportsPlatform(const String& platform, bool explicitCheck) const
  76. {
  77. if (!explicitCheck && !platforms_.Size())
  78. return true;
  79. if (platforms_.Contains(platform.ToLower()))
  80. return true;
  81. return false;
  82. }
  83. bool NETCSProject::CreateProjectFolder(const String& path)
  84. {
  85. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  86. if (fileSystem->DirExists(path))
  87. return true;
  88. fileSystem->CreateDirsRecursive(path);
  89. if (!fileSystem->DirExists(path))
  90. {
  91. ATOMIC_LOGERRORF("Unable to create dir: %s", path.CString());
  92. return false;
  93. }
  94. return true;
  95. }
  96. void NETCSProject::CreateCompileItemGroup(XMLElement &projectRoot)
  97. {
  98. FileSystem* fs = GetSubsystem<FileSystem>();
  99. XMLElement igroup = projectRoot.CreateChild("ItemGroup");
  100. // Compile AssemblyInfo.cs
  101. if (!GetIsPCL() && !sharedReferences_.Size() && outputType_ != "Shared")
  102. igroup.CreateChild("Compile").SetAttribute("Include", "Properties\\AssemblyInfo.cs");
  103. for (unsigned i = 0; i < sourceFolders_.Size(); i++)
  104. {
  105. const String& sourceFolder = sourceFolders_[i];
  106. Vector<String> result;
  107. fs->ScanDir(result, sourceFolder, "*.cs", SCAN_FILES, true);
  108. for (unsigned j = 0; j < result.Size(); j++)
  109. {
  110. XMLElement compile = igroup.CreateChild("Compile");
  111. String path = sourceFolder + result[j];
  112. String relativePath;
  113. if (GetRelativePath(projectPath_, GetPath(path), relativePath))
  114. {
  115. path = relativePath + GetFileName(path) + GetExtension(path);
  116. }
  117. // IMPORTANT: / Slash direction breaks intellisense :/
  118. path.Replace('/', '\\');
  119. compile.SetAttribute("Include", path.CString());
  120. String link = result[j];
  121. // put generated files into generated folder
  122. if (sourceFolder.Contains("Generated") && sourceFolder.Contains("CSharp") && sourceFolder.Contains("Packages"))
  123. {
  124. link = "Generated\\" + result[j];
  125. }
  126. link.Replace('/', '\\');
  127. compile.CreateChild("Link").SetValue(link);
  128. }
  129. }
  130. }
  131. void NETProjectBase::CopyXMLElementRecursive(XMLElement source, XMLElement dest)
  132. {
  133. Vector<String> attrNames = source.GetAttributeNames();
  134. for (unsigned i = 0; i < attrNames.Size(); i++)
  135. {
  136. String value = source.GetAttribute(attrNames[i]);
  137. dest.SetAttribute(attrNames[i], value);
  138. }
  139. dest.SetValue(source.GetValue());
  140. XMLElement child = source.GetChild();
  141. while (child.NotNull() && child.GetName().Length())
  142. {
  143. XMLElement childDest = dest.CreateChild(child.GetName());
  144. CopyXMLElementRecursive(child, childDest);
  145. child = child.GetNext();
  146. }
  147. }
  148. void NETCSProject::CreateReferencesItemGroup(XMLElement &projectRoot)
  149. {
  150. ToolEnvironment* tenv = GetSubsystem<ToolEnvironment>();
  151. const String atomicProjectPath = projectGen_->GetAtomicProjectPath();
  152. XMLElement xref;
  153. XMLElement igroup = projectRoot.CreateChild("ItemGroup");
  154. for (unsigned i = 0; i < references_.Size(); i++)
  155. {
  156. String ref = references_[i];
  157. String platform;
  158. if (ref.StartsWith("AtomicNET"))
  159. {
  160. if (GetIsPCL())
  161. {
  162. ref = "AtomicNET";
  163. platform = "Portable";
  164. }
  165. else if (SupportsDesktop())
  166. {
  167. ref = "AtomicNET";
  168. platform = "Desktop";
  169. }
  170. else if (SupportsPlatform("android"))
  171. {
  172. if (ref != "AtomicNET.Android.SDL")
  173. ref = "AtomicNET";
  174. platform = "Android";
  175. }
  176. else if (SupportsPlatform("ios"))
  177. {
  178. ref = "AtomicNET";
  179. platform = "iOS";
  180. }
  181. // When building Atomic Projects, assemblies will be in the Lib folder
  182. String config = "Lib";
  183. // If we're not building a project, assemblies will be either Debug or Release
  184. if (!atomicProjectPath.Length())
  185. {
  186. #ifdef ATOMIC_DEBUG
  187. config = "Debug";
  188. #else
  189. config = "Release";
  190. #endif
  191. }
  192. if (platform.Length())
  193. {
  194. String relativeAssemblyPath;
  195. if (GetRelativePath(projectPath_, GetParentPath(projectGen_->GetSolution()->GetOutputPath()), relativeAssemblyPath))
  196. {
  197. xref = igroup.CreateChild("Reference");
  198. xref.SetAttribute("Include", ref);
  199. // Specify the assembly path, which is the same based on native build
  200. String assemblyPath = relativeAssemblyPath + ToString("%s/%s/%s.dll", config.CString(), platform.CString(), ref.CString());
  201. // Setup hint paths with both release/debug config, although they point to same assembly, they don't need to
  202. XMLElement hintPath = xref.CreateChild("HintPath");
  203. hintPath.SetAttribute("Condition", "'$(Configuration)' == 'Release'");
  204. hintPath.SetValue(assemblyPath);
  205. hintPath = xref.CreateChild("HintPath");
  206. hintPath.SetAttribute("Condition", "'$(Configuration)' == 'Debug'");
  207. hintPath.SetValue(assemblyPath);
  208. }
  209. else
  210. {
  211. ATOMIC_LOGERRORF("NETCSProject::CreateReferencesItemGroup - Unable to get relative path from %s to solution", projectPath_.CString());
  212. }
  213. }
  214. continue;
  215. }
  216. // NuGet project
  217. if (ref.StartsWith("<"))
  218. {
  219. XMLFile xmlFile(context_);
  220. if (!xmlFile.FromString(ref))
  221. {
  222. ATOMIC_LOGERROR("NETCSProject::CreateReferencesItemGroup - Unable to parse reference XML");
  223. }
  224. xref = igroup.CreateChild("Reference");
  225. CopyXMLElementRecursive(xmlFile.GetRoot(), xref);
  226. continue;
  227. }
  228. xref = igroup.CreateChild("Reference");
  229. xref.SetAttribute("Include", ref);
  230. }
  231. if (atomicProjectPath.Length())
  232. {
  233. String resourceDir = AddTrailingSlash(atomicProjectPath) + "Resources/";
  234. Vector<String> result;
  235. GetSubsystem<FileSystem>()->ScanDir(result, resourceDir , "*.dll", SCAN_FILES, true);
  236. for (unsigned j = 0; j < result.Size(); j++)
  237. {
  238. String path = resourceDir + result[j];
  239. String relativePath;
  240. if (GetRelativePath(projectPath_, GetPath(path), relativePath))
  241. {
  242. if (projectGen_->GetCSProjectByName(GetFileName(path)))
  243. continue;
  244. path = relativePath + GetFileName(path) + GetExtension(path);
  245. }
  246. xref = igroup.CreateChild("Reference");
  247. xref.SetAttribute("Include", path);
  248. }
  249. }
  250. }
  251. void NETCSProject::CreatePackagesItemGroup(XMLElement &projectRoot)
  252. {
  253. if (!packages_.Size())
  254. return;
  255. XMLElement xref;
  256. XMLElement igroup = projectRoot.CreateChild("ItemGroup");
  257. xref = igroup.CreateChild("None");
  258. xref.SetAttribute("Include", "packages.config");
  259. XMLFile packageConfig(context_);
  260. XMLElement packageRoot = packageConfig.CreateRoot("packages");
  261. for (unsigned i = 0; i < packages_.Size(); i++)
  262. {
  263. XMLFile xmlFile(context_);
  264. if (!xmlFile.FromString(packages_[i]))
  265. {
  266. ATOMIC_LOGERROR("NETCSProject::CreatePackagesItemGroup - Unable to parse package xml");
  267. }
  268. xref = packageRoot.CreateChild("package");
  269. CopyXMLElementRecursive(xmlFile.GetRoot(), xref);
  270. }
  271. SharedPtr<File> output(new File(context_, GetSanitizedPath(projectPath_ + "packages.config"), FILE_WRITE));
  272. String source = packageConfig.ToString();
  273. output->Write(source.CString(), source.Length());
  274. }
  275. void NETCSProject::GetAssemblySearchPaths(String& paths)
  276. {
  277. paths.Clear();
  278. ToolEnvironment* tenv = GetSubsystem<ToolEnvironment>();
  279. Vector<String> searchPaths;
  280. if (assemblySearchPaths_.Length())
  281. searchPaths.Push(assemblySearchPaths_);
  282. paths.Join(searchPaths, ";");
  283. }
  284. void NETCSProject::ProcessDefineConstants(StringVector& constants)
  285. {
  286. const Vector<String>& globalConstants = projectGen_->GetGlobalDefineConstants();
  287. constants += globalConstants;
  288. if (constants.Contains("ATOMIC_IOS") || constants.Contains("ATOMIC_ANDROID"))
  289. constants.Push("ATOMIC_MOBILE");
  290. }
  291. void NETCSProject::CreateReleasePropertyGroup(XMLElement &projectRoot)
  292. {
  293. XMLElement pgroup = projectRoot.CreateChild("PropertyGroup");
  294. if (playerApplication_ && SupportsPlatform("ios"))
  295. pgroup.SetAttribute("Condition", " '$(Configuration)|$(Platform)' == 'Release|iPhone' ");
  296. else
  297. pgroup.SetAttribute("Condition", " '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ");
  298. pgroup.CreateChild("Optimize").SetValue("true");
  299. String outputPath = assemblyOutputPath_;
  300. outputPath.Replace("$ATOMIC_CONFIG$", "Release");
  301. if (IsAbsolutePath(outputPath))
  302. {
  303. String atomicProjectPath = projectGen_->GetAtomicProjectPath();
  304. if (atomicProjectPath.Length())
  305. {
  306. if (!GetRelativeProjectPath(outputPath, projectPath_, outputPath))
  307. {
  308. ATOMIC_LOGERRORF("NETCSProject::CreateReleasePropertyGroup - unable to get relative output path");
  309. }
  310. }
  311. }
  312. pgroup.CreateChild("OutputPath").SetValue(outputPath);
  313. Vector<String> constants;
  314. constants.Push("TRACE");
  315. constants += defineConstants_;
  316. ProcessDefineConstants(constants);
  317. pgroup.CreateChild("DefineConstants").SetValue(String::Joined(constants, ";").CString());
  318. pgroup.CreateChild("ErrorReport").SetValue("prompt");
  319. pgroup.CreateChild("WarningLevel").SetValue("4");
  320. pgroup.CreateChild("ConsolePause").SetValue("false");
  321. pgroup.CreateChild("AllowUnsafeBlocks").SetValue("true");
  322. // 1591 - Don't warn on missing documentation
  323. // 1570 - malformed xml, remove once (https://github.com/AtomicGameEngine/AtomicGameEngine/issues/1161) resolved
  324. pgroup.CreateChild("NoWarn").SetValue("1591;1570");
  325. if (genAssemblyDocFile_)
  326. {
  327. pgroup.CreateChild("DocumentationFile").SetValue(outputPath + assemblyName_ + ".xml");
  328. }
  329. if (SupportsDesktop())
  330. {
  331. pgroup.CreateChild("DebugType").SetValue(GetIsPCL() ? "pdbonly": "full");
  332. if (!GetIsPCL())
  333. pgroup.CreateChild("PlatformTarget").SetValue("x64");
  334. #ifndef ATOMIC_PLATFORM_WINDOWS
  335. String startArguments;
  336. #ifndef ATOMIC_DEV_BUILD
  337. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  338. #ifdef ATOMIC_PLATFORM_OSX
  339. startArguments += ToString("--resourcePrefix \"%s\" ", (fileSystem->GetProgramDir() + "../Resources/").CString());
  340. #else
  341. startArguments += ToString("--resourcePrefix \"%s\" ", (fileSystem->GetProgramDir() + "Resources/").CString());
  342. #endif
  343. #endif
  344. startArguments += ToString("--project \"%s\"", projectGen_->GetAtomicProjectPath().CString());
  345. pgroup.CreateChild("Commandlineparameters").SetValue(startArguments);
  346. #endif
  347. }
  348. else
  349. {
  350. if (SupportsPlatform("android"))
  351. {
  352. pgroup.CreateChild("DebugType").SetValue("pdbonly");
  353. if (outputType_.ToLower() != "library")
  354. {
  355. pgroup.CreateChild("AndroidUseSharedRuntime").SetValue("False");
  356. pgroup.CreateChild("AndroidLinkMode").SetValue("SdkOnly");
  357. }
  358. }
  359. else if (playerApplication_ && SupportsPlatform("ios"))
  360. {
  361. pgroup.CreateChild("DebugType").SetValue("none");
  362. pgroup.CreateChild("MtouchArch").SetValue("ARMv7, ARM64");
  363. pgroup.CreateChild("CodesignEntitlements").SetValue(GetSanitizedPath(codesignEntitlements_));
  364. pgroup.CreateChild("CodesignKey").SetValue("iPhone Developer");
  365. pgroup.CreateChild("MtouchDebug").SetValue("true");
  366. pgroup.CreateChild("MtouchOptimizePNGs").SetValue("False");
  367. }
  368. }
  369. }
  370. void NETCSProject::CreateDebugPropertyGroup(XMLElement &projectRoot)
  371. {
  372. XMLElement pgroup = projectRoot.CreateChild("PropertyGroup");
  373. if (playerApplication_ && SupportsPlatform("ios"))
  374. pgroup.SetAttribute("Condition", " '$(Configuration)|$(Platform)' == 'Debug|iPhone' ");
  375. else
  376. pgroup.SetAttribute("Condition", " '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ");
  377. pgroup.CreateChild("Optimize").SetValue("false");
  378. String outputPath = assemblyOutputPath_;
  379. outputPath.Replace("$ATOMIC_CONFIG$", "Debug");
  380. if (IsAbsolutePath(outputPath))
  381. {
  382. String atomicProjectPath = projectGen_->GetAtomicProjectPath();
  383. if (atomicProjectPath.Length())
  384. {
  385. if (!GetRelativeProjectPath(outputPath, projectPath_, outputPath))
  386. {
  387. ATOMIC_LOGERRORF("NETCSProject::CreateDebugPropertyGroup - unable to get relative output path");
  388. }
  389. }
  390. }
  391. pgroup.CreateChild("OutputPath").SetValue(outputPath);
  392. Vector<String> constants;
  393. constants.Push("DEBUG");
  394. constants.Push("TRACE");
  395. constants += defineConstants_;
  396. ProcessDefineConstants(constants);
  397. pgroup.CreateChild("DefineConstants").SetValue(String::Joined(constants, ";").CString());
  398. pgroup.CreateChild("ErrorReport").SetValue("prompt");
  399. pgroup.CreateChild("WarningLevel").SetValue("4");
  400. pgroup.CreateChild("ConsolePause").SetValue("false");
  401. pgroup.CreateChild("AllowUnsafeBlocks").SetValue("true");
  402. // 1591 - Don't warn on missing documentation
  403. // 1570 - malformed xml, remove once (https://github.com/AtomicGameEngine/AtomicGameEngine/issues/1161) resolved
  404. pgroup.CreateChild("NoWarn").SetValue("1591;1570");
  405. pgroup.CreateChild("DebugSymbols").SetValue("true");
  406. if (genAssemblyDocFile_)
  407. {
  408. pgroup.CreateChild("DocumentationFile").SetValue(outputPath + assemblyName_ + ".xml");
  409. }
  410. if (SupportsDesktop())
  411. {
  412. pgroup.CreateChild("DebugType").SetValue(GetIsPCL() ? "pdbonly": "full");
  413. if (!GetIsPCL())
  414. pgroup.CreateChild("PlatformTarget").SetValue("x64");
  415. #ifndef ATOMIC_PLATFORM_WINDOWS
  416. String startArguments;
  417. #ifndef ATOMIC_DEV_BUILD
  418. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  419. #ifdef ATOMIC_PLATFORM_OSX
  420. startArguments += ToString("--resourcePrefix \"%s\" ", (fileSystem->GetProgramDir() + "../Resources/").CString());
  421. #else
  422. startArguments += ToString("--resourcePrefix \"%s\" ", (fileSystem->GetProgramDir() + "Resources/").CString());
  423. #endif
  424. #endif
  425. startArguments += ToString("--project \"%s\"", projectGen_->GetAtomicProjectPath().CString());
  426. pgroup.CreateChild("Commandlineparameters").SetValue(startArguments);
  427. #endif
  428. }
  429. else
  430. {
  431. pgroup.CreateChild("DebugType").SetValue(GetIsPCL() ? "pdbonly": "full");
  432. if (androidApplication_)
  433. {
  434. pgroup.CreateChild("AndroidUseSharedRuntime").SetValue("False");
  435. pgroup.CreateChild("AndroidLinkMode").SetValue("None");
  436. pgroup.CreateChild("EmbedAssembliesIntoApk").SetValue("True");
  437. pgroup.CreateChild("BundleAssemblies").SetValue("False");
  438. pgroup.CreateChild("AndroidCreatePackagePerAbi").SetValue("False");
  439. pgroup.CreateChild("Debugger").SetValue("Xamarin");
  440. pgroup.CreateChild("AndroidEnableMultiDex").SetValue("False");
  441. pgroup.CreateChild("AndroidSupportedAbis").SetValue("armeabi-v7a");
  442. }
  443. else if (playerApplication_ && SupportsPlatform("ios"))
  444. {
  445. pgroup.CreateChild("MtouchArch").SetValue("ARMv7, ARM64");
  446. pgroup.CreateChild("CodesignEntitlements").SetValue(GetSanitizedPath(codesignEntitlements_));
  447. pgroup.CreateChild("CodesignKey").SetValue("iPhone Developer");
  448. pgroup.CreateChild("MtouchDebug").SetValue("true");
  449. pgroup.CreateChild("MtouchFastDev").SetValue("true");
  450. pgroup.CreateChild("IpaPackageName").SetValue("");
  451. pgroup.CreateChild("OptimizePNGs").SetValue("false");
  452. pgroup.CreateChild("MtouchOptimizePNGs").SetValue("False");
  453. }
  454. }
  455. }
  456. void NETCSProject::CreateApplicationItems(XMLElement &projectRoot)
  457. {
  458. ToolEnvironment* tenv = GetSubsystem<ToolEnvironment>();
  459. XMLElement itemGroup = projectRoot.CreateChild("ItemGroup");
  460. if (SupportsDesktop())
  461. {
  462. // AtomicNETNative
  463. XMLElement atomicNETNativeDLL = itemGroup.CreateChild("None");
  464. #ifdef ATOMIC_DEBUG
  465. String config = "Debug";
  466. #else
  467. String config = "Release";
  468. #endif
  469. #ifdef ATOMIC_PLATFORM_WINDOWS
  470. String platform = "Windows";
  471. String filename = "AtomicNETNative.dll";
  472. #elif defined(ATOMIC_PLATFORM_OSX)
  473. String platform = "Mac";
  474. String filename = "libAtomicNETNative.dylib";
  475. #elif defined(ATOMIC_PLATFORM_LINUX)
  476. String platform = "Linux";
  477. String filename = "libAtomicNETNative.so";
  478. #endif
  479. String relativeNativePath;
  480. String configPath = config;
  481. if (projectGen_->GetAtomicProjectPath().Length())
  482. configPath = "Lib";
  483. if (GetRelativePath(projectPath_, GetParentPath(projectGen_->GetSolution()->GetOutputPath()), relativeNativePath))
  484. {
  485. String nativePath = relativeNativePath + configPath + "/Native/" + platform + "/" + filename;
  486. atomicNETNativeDLL.SetAttribute("Include", nativePath);
  487. atomicNETNativeDLL.CreateChild("Link").SetValue(filename);
  488. atomicNETNativeDLL.CreateChild("CopyToOutputDirectory").SetValue("PreserveNewest");
  489. #ifdef ATOMIC_PLATFORM_WINDOWS
  490. XMLElement d3dCompilerDLL = itemGroup.CreateChild("None");
  491. String d3dCompilerPath = relativeNativePath + configPath + "/Native/" + platform + "/D3DCompiler_47.dll";
  492. d3dCompilerDLL.SetAttribute("Include", d3dCompilerPath);
  493. d3dCompilerDLL.CreateChild("Link").SetValue("D3DCompiler_47.dll");
  494. d3dCompilerDLL.CreateChild("CopyToOutputDirectory").SetValue("PreserveNewest");
  495. #endif
  496. }
  497. }
  498. else
  499. {
  500. const String& projectPath = projectGen_->GetAtomicProjectPath();
  501. if (!playerApplication_ || !projectPath.Length())
  502. return;
  503. if (androidApplication_)
  504. {
  505. XMLElement androidAsset = itemGroup.CreateChild("AndroidAsset");
  506. androidAsset.SetAttribute("Include", projectPath + "AtomicNET/Resources/AtomicResources.pak");
  507. androidAsset.CreateChild("Link").SetValue("Assets\\AtomicResources.pak");
  508. }
  509. else
  510. {
  511. XMLElement bundleResource = itemGroup.CreateChild("BundleResource");
  512. bundleResource.SetAttribute("Include", projectPath + "AtomicNET/Resources/AtomicResources.pak");
  513. bundleResource.CreateChild("Link").SetValue("Resources\\AtomicResources.pak");
  514. bundleResource.CreateChild("CopyToOutputDirectory").SetValue("PreserveNewest");
  515. }
  516. }
  517. }
  518. void NETCSProject::CreateIOSItems(XMLElement &projectRoot)
  519. {
  520. XMLElement iosGroup = projectRoot.CreateChild("ItemGroup");
  521. if (objcBindingApiDefinition_.Length())
  522. {
  523. iosGroup.CreateChild("ObjcBindingApiDefinition").SetAttribute("Include", GetSanitizedPath(objcBindingApiDefinition_));
  524. }
  525. if (name_ == "AtomicNET.iOS")
  526. {
  527. ToolEnvironment* tenv = GetSubsystem<ToolEnvironment>();
  528. #ifdef ATOMIC_DEBUG
  529. String config = "Debug";
  530. #else
  531. String config = "Release";
  532. #endif
  533. String nativePath = AddTrailingSlash(tenv->GetAtomicNETRootDir()) + config + "/Native/iOS/AtomicNETNative.framework";
  534. iosGroup.CreateChild("ObjcBindingNativeFramework").SetAttribute("Include", GetSanitizedPath(nativePath));
  535. // framework copy
  536. XMLElement none = iosGroup.CreateChild("None");
  537. none.SetAttribute("Include", nativePath + ".zip");
  538. none.CreateChild("Link").SetValue("AtomicNETNative.framework.zip");
  539. none.CreateChild("CopyToOutputDirectory").SetValue("Always");
  540. }
  541. else if (playerApplication_)
  542. {
  543. XMLElement plist = iosGroup.CreateChild("None");
  544. plist.SetAttribute("Include", GetSanitizedPath(infoPList_));
  545. plist.CreateChild("Link").SetValue("Info.plist");
  546. XMLElement entitlements = iosGroup.CreateChild("Content");
  547. entitlements.SetAttribute("Include", GetSanitizedPath(codesignEntitlements_));
  548. entitlements.CreateChild("Link").SetValue("Entitlements.plist");
  549. }
  550. }
  551. void NETCSProject::CreateAndroidItems(XMLElement &projectRoot)
  552. {
  553. if (!libraryProjectZips_.Size())
  554. {
  555. }
  556. if (libraryProjectZips_.Size())
  557. {
  558. XMLElement libraryGroup = projectRoot.CreateChild("ItemGroup");
  559. for (unsigned i = 0; i < libraryProjectZips_.Size(); i++)
  560. {
  561. libraryGroup.CreateChild("LibraryProjectZip").SetAttribute("Include", libraryProjectZips_[i].CString());
  562. }
  563. }
  564. if (transformFiles_.Size())
  565. {
  566. XMLElement transformGroup = projectRoot.CreateChild("ItemGroup");
  567. for (unsigned i = 0; i < transformFiles_.Size(); i++)
  568. {
  569. transformGroup.CreateChild("TransformFile").SetAttribute("Include", transformFiles_[i].CString());
  570. }
  571. }
  572. if (!importProjects_.Size())
  573. {
  574. projectRoot.CreateChild("Import").SetAttribute("Project", "$(MSBuildExtensionsPath)\\Xamarin\\Android\\Xamarin.Android.CSharp.targets");
  575. }
  576. if (androidApplication_)
  577. {
  578. // TODO: other abi
  579. ToolEnvironment* tenv = GetSubsystem<ToolEnvironment>();
  580. #ifdef ATOMIC_DEBUG
  581. String config = "Debug";
  582. #else
  583. String config = "Release";
  584. #endif
  585. // TODO: more than armeabi-v7a (which this is)
  586. String nativePath = AddTrailingSlash(tenv->GetAtomicNETRootDir()) + config + "/Native/Android/libAtomicNETNative.so";
  587. XMLElement nativeLibrary = projectRoot.CreateChild("ItemGroup").CreateChild("AndroidNativeLibrary");
  588. nativeLibrary.SetAttribute("Include", nativePath);
  589. nativeLibrary.CreateChild("Link").SetValue("Libs\\armeabi-v7a\\libAtomicNETNative.so");
  590. XMLElement resourceGroup = projectRoot.CreateChild("ItemGroup");
  591. String relativePath;
  592. if (GetRelativeProjectPath("$ATOMIC_PROJECT_ROOT$/Project/AtomicNET/Platforms/Android/Resources/values/Strings.xml", projectPath_, relativePath))
  593. {
  594. relativePath.Replace("/", "\\");
  595. XMLElement strings = resourceGroup.CreateChild("AndroidResource");
  596. strings.SetAttribute("Include", relativePath);
  597. // Link has to exist for manifest to find resource!
  598. strings.CreateChild("Link").SetValue("Resources\\values\\Strings.xml");
  599. }
  600. else
  601. {
  602. ATOMIC_LOGERROR("Unabled to get relative path for Strings.xml");
  603. }
  604. if (GetRelativeProjectPath("$ATOMIC_PROJECT_ROOT$/Project/AtomicNET/Platforms/Android/Resources/drawable/icon.png", projectPath_, relativePath))
  605. {
  606. relativePath.Replace("/", "\\");
  607. XMLElement icon = resourceGroup.CreateChild("AndroidResource");
  608. icon.SetAttribute("Include", relativePath);
  609. // Link has to exist for manifest to find resource!
  610. icon.CreateChild("Link").SetValue("Resources\\drawable\\icon.png");
  611. }
  612. else
  613. {
  614. ATOMIC_LOGERROR("Unabled to get relative path for Icon.png");
  615. }
  616. }
  617. }
  618. void NETCSProject::CreateAssemblyInfo()
  619. {
  620. String info = "using System.Reflection;\nusing System.Runtime.CompilerServices;\nusing System.Runtime.InteropServices;\n\n\n";
  621. info += ToString("[assembly:AssemblyTitle(\"%s\")]\n", name_.CString());
  622. info += "[assembly:AssemblyDescription(\"\")]\n";
  623. info += "[assembly:AssemblyConfiguration(\"\")]\n";
  624. info += "[assembly:AssemblyCompany(\"\")]\n";
  625. info += ToString("[assembly:AssemblyProduct(\"%s\")]\n", name_.CString());
  626. info += "\n\n\n";
  627. info += "[assembly:ComVisible(false)]\n";
  628. info += "\n\n";
  629. info += ToString("[assembly:Guid(\"%s\")]\n", projectGuid_.CString());
  630. info += "\n\n";
  631. info += "[assembly:AssemblyVersion(\"1.0.0.0\")]\n";
  632. info += "[assembly:AssemblyFileVersion(\"1.0.0.0\")]\n";
  633. SharedPtr<File> output(new File(context_, GetSanitizedPath(projectPath_ + "Properties/AssemblyInfo.cs"), FILE_WRITE));
  634. output->Write(info.CString(), info.Length());
  635. }
  636. bool NETCSProject::GetRelativeProjectPath(const String& fromPath, const String& toPath, String& output)
  637. {
  638. String path = fromPath;
  639. ReplacePathStrings(path);
  640. path = GetSanitizedPath(path);
  641. String relativePath;
  642. if (GetRelativePath(projectPath_, GetPath(path), relativePath))
  643. {
  644. path = relativePath + GetFileName(path) + GetExtension(path);
  645. output = path;
  646. return true;
  647. }
  648. output = fromPath;
  649. return false;
  650. }
  651. void NETCSProject::CreateMainPropertyGroup(XMLElement& projectRoot)
  652. {
  653. XMLElement pgroup = projectRoot.CreateChild("PropertyGroup");
  654. // Configuration
  655. XMLElement config = pgroup.CreateChild("Configuration");
  656. config.SetAttribute("Condition", " '$(Configuration)' == '' ");
  657. config.SetValue("Debug");
  658. // Platform
  659. XMLElement platform = pgroup.CreateChild("Platform");
  660. platform.SetAttribute("Condition", " '$(Platform)' == '' ");
  661. if (playerApplication_ && SupportsPlatform("ios"))
  662. platform.SetValue("iPhone");
  663. else
  664. platform.SetValue("AnyCPU");
  665. // ProjectGuid
  666. XMLElement guid = pgroup.CreateChild("ProjectGuid");
  667. guid.SetValue("{" + projectGuid_ + "}");
  668. // OutputType
  669. XMLElement outputType = pgroup.CreateChild("OutputType");
  670. String oType = outputType_;
  671. #ifdef ATOMIC_PLATFORM_WINDOWS
  672. #ifndef ATOMIC_DEBUG
  673. if (oType.ToLower() == "exe")
  674. {
  675. // use windows subsystem for release builds
  676. // TODO: make this an option in the json?
  677. oType = "WinExe";
  678. }
  679. #endif
  680. #endif
  681. outputType.SetValue(oType);
  682. pgroup.CreateChild("AppDesignerFolder").SetValue("Properties");
  683. // RootNamespace
  684. XMLElement rootNamespace = pgroup.CreateChild("RootNamespace");
  685. rootNamespace.SetValue(rootNamespace_);
  686. // AssemblyName
  687. XMLElement assemblyName = pgroup.CreateChild("AssemblyName");
  688. assemblyName.SetValue(assemblyName_);
  689. pgroup.CreateChild("FileAlignment").SetValue("512");
  690. if (projectTypeGuids_.Size())
  691. {
  692. pgroup.CreateChild("ProjectTypeGuids").SetValue(String::Joined(projectTypeGuids_, ";"));
  693. }
  694. if (SupportsDesktop())
  695. {
  696. pgroup.CreateChild("TargetFrameworkVersion").SetValue("v4.5");
  697. }
  698. else
  699. {
  700. pgroup.CreateChild("ProductVersion").SetValue("8.0.30703");
  701. pgroup.CreateChild("SchemaVersion").SetValue("2.0");
  702. if (SupportsPlatform("ios"))
  703. {
  704. pgroup.CreateChild("IPhoneResourcePrefix").SetValue("Resources");
  705. }
  706. else
  707. {
  708. pgroup.CreateChild("TargetFrameworkVersion").SetValue("v6.0");
  709. }
  710. if (SupportsPlatform("android"))
  711. {
  712. if (!projectTypeGuids_.Size())
  713. {
  714. pgroup.CreateChild("ProjectTypeGuids").SetValue("{EFBA0AD7-5A72-4C68-AF49-83D382785DCF};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}");
  715. }
  716. pgroup.CreateChild("AndroidUseLatestPlatformSdk").SetValue("True");
  717. if (!androidApplication_)
  718. {
  719. // 10368E6C-D01B-4462-8E8B-01FC667A7035 is a binding library
  720. if (!projectTypeGuids_.Contains("{10368E6C-D01B-4462-8E8B-01FC667A7035}"))
  721. pgroup.CreateChild("GenerateSerializationAssemblies").SetValue("Off");
  722. }
  723. else
  724. {
  725. // Android Application
  726. pgroup.CreateChild("AndroidApplication").SetValue("true");
  727. // AndroidManifest.xml must reside in Properties/AndroidManifest.xml, which introduces sync issues :/
  728. pgroup.CreateChild("AndroidManifest").SetValue("Properties\\AndroidManifest.xml");
  729. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  730. String manifestSourceFile = "$ATOMIC_PROJECT_ROOT$/Project/AtomicNET/Platforms/Android/Properties/AndroidManifest.xml";
  731. ReplacePathStrings(manifestSourceFile);
  732. manifestSourceFile = GetSanitizedPath(manifestSourceFile);
  733. if (fileSystem->FileExists(manifestSourceFile))
  734. {
  735. String manifestDest = GetSanitizedPath(projectPath_ + "Properties/");
  736. if (!fileSystem->DirExists(manifestDest))
  737. {
  738. fileSystem->CreateDirs(GetSanitizedPath(projectGen_->GetAtomicProjectPath()), ToString("/AtomicNET/Solution/%s/Properties/", name_.CString()));
  739. }
  740. if (fileSystem->DirExists(manifestDest))
  741. {
  742. if (!fileSystem->Copy(manifestSourceFile, manifestDest + "AndroidManifest.xml"))
  743. {
  744. ATOMIC_LOGERRORF("Unable to copy AndroidManifest from %s to %s", manifestSourceFile.CString(), manifestDest.CString());
  745. }
  746. }
  747. else
  748. {
  749. ATOMIC_LOGERRORF("Unable to create folder %s for AndroidManifest.xml", manifestDest.CString());
  750. }
  751. }
  752. else
  753. {
  754. ATOMIC_LOGERRORF("No AndroidManifest.xml, project will not deploy (%s)", manifestSourceFile.CString());
  755. }
  756. String relativePath;
  757. if (GetRelativeProjectPath("$ATOMIC_PROJECT_ROOT$/Project/AtomicNET/Platforms/Android/Resources/Resource.Designer.cs", projectPath_, relativePath))
  758. {
  759. relativePath.Replace("/", "\\");
  760. pgroup.CreateChild("AndroidResgenFile").SetValue(relativePath);
  761. }
  762. else
  763. {
  764. ATOMIC_LOGERROR("Unabled to get relative path for AndroidResgenFile");
  765. }
  766. pgroup.CreateChild("GenerateSerializationAssemblies").SetValue("Off");
  767. }
  768. }
  769. }
  770. if (targetFrameworkProfile_.Length())
  771. {
  772. pgroup.CreateChild("TargetFrameworkProfile").SetValue(targetFrameworkProfile_);
  773. }
  774. }
  775. bool NETCSProject::GenerateShared()
  776. {
  777. // .shproj
  778. XMLElement project = xmlFile_->CreateRoot("Project");
  779. project.SetAttribute("DefaultTargets", "Build");
  780. project.SetAttribute("ToolsVersion", "14.0");
  781. project.SetAttribute("DefaultTargets", "Build");
  782. project.SetAttribute("xmlns", "http://schemas.microsoft.com/developer/msbuild/2003");
  783. // Project Group
  784. XMLElement projectGroup = project.CreateChild("PropertyGroup");
  785. projectGroup.SetAttribute("Label", "Globals");
  786. projectGroup.CreateChild("ProjectGuid").SetValue(projectGuid_);
  787. projectGroup.CreateChild("MinimumVisualStudioVersion").SetValue("14.0");
  788. XMLElement import = project.CreateChild("Import");
  789. import.SetAttribute("Project", "$(MSBuildExtensionsPath)\\$(MSBuildToolsVersion)\\Microsoft.Common.props");
  790. import.SetAttribute("Condition", "Exists('$(MSBuildExtensionsPath)\\$(MSBuildToolsVersion)\\Microsoft.Common.props')");
  791. import = project.CreateChild("Import");
  792. import.SetAttribute("Project", "$(MSBuildExtensionsPath32)\\Microsoft\\VisualStudio\\v$(VisualStudioVersion)\\CodeSharing\\Microsoft.CodeSharing.Common.Default.props");
  793. import = project.CreateChild("Import");
  794. import.SetAttribute("Project", "$(MSBuildExtensionsPath32)\\Microsoft\\VisualStudio\\v$(VisualStudioVersion)\\CodeSharing\\Microsoft.CodeSharing.Common.props");
  795. import = project.CreateChild("Import");
  796. import.SetAttribute("Project", ToString("%s.projitems", name_.CString()));
  797. import.SetAttribute("Label", "Shared");
  798. import = project.CreateChild("Import");
  799. import.SetAttribute("Project", "$(MSBuildExtensionsPath32)\\Microsoft\\VisualStudio\\v$(VisualStudioVersion)\\CodeSharing\\Microsoft.CodeSharing.CSharp.targets");
  800. String projectSource = xmlFile_->ToString();
  801. SharedPtr<File> output(new File(context_, GetSanitizedPath(projectPath_ + name_ + ".shproj"), FILE_WRITE));
  802. output->Write(projectSource.CString(), projectSource.Length());
  803. // projitems
  804. SharedPtr<XMLFile> itemsXMLFile(new XMLFile(context_));
  805. XMLElement itemsProject = itemsXMLFile->CreateRoot("Project");
  806. itemsProject.SetAttribute("xmlns", "http://schemas.microsoft.com/developer/msbuild/2003");
  807. XMLElement propertyGroup = itemsProject.CreateChild("PropertyGroup");
  808. propertyGroup.CreateChild("MSBuildAllProjects").SetValue("$(MSBuildAllProjects);$(MSBuildThisFileFullPath)");
  809. propertyGroup.CreateChild("HasSharedItems").SetValue("true");
  810. propertyGroup.CreateChild("SharedGUID").SetValue(projectGuid_);
  811. propertyGroup = itemsProject.CreateChild("PropertyGroup");
  812. propertyGroup.SetAttribute("Label", "Configuration");
  813. propertyGroup.CreateChild("Import_RootNamespace").SetValue("AtomicEngine");
  814. CreateCompileItemGroup(itemsProject);
  815. String itemSource = itemsXMLFile->ToString();
  816. SharedPtr<File> itemsOutput(new File(context_, GetSanitizedPath(projectPath_ + name_ + ".projitems"), FILE_WRITE));
  817. itemsOutput->Write(itemSource.CString(), itemSource.Length());
  818. return true;
  819. }
  820. bool NETCSProject::GenerateStandard()
  821. {
  822. ToolEnvironment* tenv = GetSubsystem<ToolEnvironment>();
  823. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  824. NETSolution* solution = projectGen_->GetSolution();
  825. XMLElement project = xmlFile_->CreateRoot("Project");
  826. project.SetAttribute("DefaultTargets", "Build");
  827. project.SetAttribute("ToolsVersion", "14.0");
  828. project.SetAttribute("DefaultTargets", "Build");
  829. project.SetAttribute("xmlns", "http://schemas.microsoft.com/developer/msbuild/2003");
  830. XMLElement import = project.CreateChild("Import");
  831. import.SetAttribute("Project", "$(MSBuildExtensionsPath)\\$(MSBuildToolsVersion)\\Microsoft.Common.props");
  832. import.SetAttribute("Condition", "Exists('$(MSBuildExtensionsPath)\\$(MSBuildToolsVersion)\\Microsoft.Common.props')");
  833. CreateMainPropertyGroup(project);
  834. CreateDebugPropertyGroup(project);
  835. CreateReleasePropertyGroup(project);
  836. CreateReferencesItemGroup(project);
  837. CreateCompileItemGroup(project);
  838. CreatePackagesItemGroup(project);
  839. if (SupportsPlatform("android"))
  840. {
  841. CreateAndroidItems(project);
  842. }
  843. if (SupportsPlatform("ios"))
  844. {
  845. CreateIOSItems(project);
  846. }
  847. if (SupportsDesktop() && !GetIsPCL())
  848. project.CreateChild("Import").SetAttribute("Project", "$(MSBuildToolsPath)\\Microsoft.CSharp.targets");
  849. if (outputType_.ToLower() == "exe" || androidApplication_)
  850. {
  851. CreateApplicationItems(project);
  852. }
  853. if (!GetIsPCL() && !sharedReferences_.Size() && outputType_ != "Shared")
  854. CreateAssemblyInfo();
  855. const String& atomicProjectPath = projectGen_->GetAtomicProjectPath();
  856. if (atomicProjectPath.Length())
  857. {
  858. // Create the AtomicProject.csproj.user file if it doesn't exist
  859. String userSettingsFilename = projectPath_ + name_ + ".csproj.user";
  860. if (!fileSystem->FileExists(userSettingsFilename))
  861. {
  862. SharedPtr<XMLFile> userSettings(new XMLFile(context_));
  863. XMLElement project = userSettings->CreateRoot("Project");
  864. project.SetAttribute("ToolsVersion", "14.0");
  865. project.SetAttribute("xmlns", "http://schemas.microsoft.com/developer/msbuild/2003");
  866. StringVector configs;
  867. configs.Push("Debug");
  868. configs.Push("Release");
  869. for (unsigned i = 0; i < configs.Size(); i++)
  870. {
  871. String cfg = configs[i];
  872. XMLElement propertyGroup = project.CreateChild("PropertyGroup");
  873. propertyGroup.SetAttribute("Condition", ToString("'$(Configuration)|$(Platform)' == '%s|AnyCPU'", cfg.CString()));
  874. String startArguments;
  875. #ifndef ATOMIC_DEV_BUILD
  876. #ifdef ATOMIC_PLATFORM_OSX
  877. startArguments += ToString("--resourcePrefix \"%s\" ", (fileSystem->GetProgramDir() + "../Resources/").CString());
  878. #else
  879. startArguments += ToString("--resourcePrefix \"%s\" ", (fileSystem->GetProgramDir() + "Resources/").CString());
  880. #endif
  881. #endif
  882. propertyGroup.CreateChild("StartAction").SetValue("Project");
  883. startArguments += ToString("--project \"%s\"", atomicProjectPath.CString());
  884. propertyGroup.CreateChild("StartArguments").SetValue(startArguments);
  885. #ifdef ATOMIC_DEBUG
  886. // When building a debug build, default native code debugging to true
  887. if (cfg == "Debug")
  888. {
  889. propertyGroup.CreateChild("EnableUnmanagedDebugging").SetValue("true");
  890. }
  891. #endif
  892. }
  893. String userSettingsSource = userSettings->ToString();
  894. SharedPtr<File> output(new File(context_, GetSanitizedPath(userSettingsFilename), FILE_WRITE));
  895. output->Write(userSettingsSource.CString(), userSettingsSource.Length());
  896. output->Close();
  897. }
  898. }
  899. for (unsigned i = 0; i < sharedReferences_.Size(); i++)
  900. {
  901. NETCSProject* sharedProject = projectGen_->GetCSProjectByName(sharedReferences_[i]);
  902. if (!sharedProject)
  903. {
  904. ATOMIC_LOGERRORF("Unable to get shared project %s", sharedReferences_[i].CString());
  905. continue;
  906. }
  907. String path = sharedProject->projectPath_ + sharedReferences_[i] + ".projitems";
  908. String relativePath;
  909. if (GetRelativePath(projectPath_, GetPath(path), relativePath))
  910. {
  911. path = relativePath + GetFileName(path) + GetExtension(path);
  912. }
  913. XMLElement shared = project.CreateChild("Import");
  914. shared.SetAttribute("Project", path);
  915. shared.SetAttribute("Label", "Shared");
  916. }
  917. for (unsigned i = 0; i < importProjects_.Size(); i++)
  918. {
  919. project.CreateChild("Import").SetAttribute("Project", importProjects_[i].CString());
  920. }
  921. // Have to come after the imports, so AfterBuild exists
  922. String projectName = "AtomicProject";
  923. if (projectGen_->GetProjectSettings())
  924. projectName = projectGen_->GetProjectSettings()->GetName();
  925. if (name_ == projectName)
  926. {
  927. XMLElement afterBuild = project.CreateChild("Target");
  928. afterBuild.SetAttribute("Name", "AfterBuild");
  929. XMLElement copy = afterBuild.CreateChild("Copy");
  930. copy.SetAttribute("SourceFiles", "$(TargetPath)");
  931. String destPath = projectPath_ + "../../../Resources/";
  932. String relativePath;
  933. String resourceDir = AddTrailingSlash(atomicProjectPath) + "Resources/";
  934. if (GetRelativePath(projectPath_, resourceDir, relativePath))
  935. {
  936. destPath = AddTrailingSlash(relativePath);
  937. }
  938. copy.SetAttribute("DestinationFolder", destPath);
  939. }
  940. String projectSource = xmlFile_->ToString();
  941. SharedPtr<File> output(new File(context_, GetSanitizedPath(projectPath_ + name_ + ".csproj"), FILE_WRITE));
  942. output->Write(projectSource.CString(), projectSource.Length());
  943. return true;
  944. }
  945. bool NETCSProject::Generate()
  946. {
  947. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  948. NETSolution* solution = projectGen_->GetSolution();
  949. projectPath_ = solution->GetOutputPath() + name_ + "/";
  950. if (!CreateProjectFolder(projectPath_))
  951. return false;
  952. if (!CreateProjectFolder(projectPath_ + "Properties"))
  953. return false;
  954. if (outputType_ == "Shared")
  955. {
  956. return GenerateShared();
  957. }
  958. return GenerateStandard();
  959. }
  960. bool NETCSProject::Load(const JSONValue& root)
  961. {
  962. name_ = root["name"].GetString();
  963. projectGuid_ = root["projectGuid"].GetString();
  964. if (!projectGuid_.Length())
  965. {
  966. ATOMIC_LOGINFOF("GUID not provided for project %s, generating one", name_.CString());
  967. projectGuid_ = projectGen_->GenerateUUID();
  968. }
  969. outputType_ = root["outputType"].GetString();
  970. androidApplication_ = root["androidApplication"].GetBool();
  971. playerApplication_ = root["playerApplication"].GetBool();
  972. genAssemblyDocFile_ = root["assemblyDocFile"].GetBool();
  973. rootNamespace_ = root["rootNamespace"].GetString();
  974. assemblyName_ = root["assemblyName"].GetString();
  975. assemblyOutputPath_ = root["assemblyOutputPath"].GetString();
  976. ReplacePathStrings(assemblyOutputPath_);
  977. assemblyOutputPath_ = GetSanitizedPath(assemblyOutputPath_);
  978. assemblySearchPaths_ = root["assemblySearchPaths"].GetString();
  979. ReplacePathStrings(assemblySearchPaths_);
  980. assemblySearchPaths_ = GetSanitizedPath(assemblySearchPaths_);
  981. const JSONArray& platforms = root["platforms"].GetArray();
  982. for (unsigned i = 0; i < platforms.Size(); i++)
  983. {
  984. String platform = platforms[i].GetString();
  985. platforms_.Push(platform.ToLower());
  986. }
  987. const JSONArray& references = root["references"].GetArray();
  988. for (unsigned i = 0; i < references.Size(); i++)
  989. {
  990. String reference = references[i].GetString();
  991. ReplacePathStrings(reference);
  992. references_.Push(reference);
  993. }
  994. const JSONArray& packages = root["packages"].GetArray();
  995. for (unsigned i = 0; i < packages.Size(); i++)
  996. {
  997. String package = packages[i].GetString();
  998. if (packages_.Find(package) != packages_.End())
  999. {
  1000. ATOMIC_LOGERRORF("Duplicate package found %s", package.CString());
  1001. continue;
  1002. }
  1003. projectGen_->GetSolution()->RegisterPackage(package);
  1004. packages_.Push(package);
  1005. }
  1006. const JSONArray& sources = root["sources"].GetArray();
  1007. for (unsigned i = 0; i < sources.Size(); i++)
  1008. {
  1009. String source = sources[i].GetString();
  1010. ReplacePathStrings(source);
  1011. sourceFolders_.Push(AddTrailingSlash(source));
  1012. }
  1013. const JSONArray& defineConstants = root["defineConstants"].GetArray();
  1014. for (unsigned i = 0; i < defineConstants.Size(); i++)
  1015. {
  1016. defineConstants_.Push(defineConstants[i].GetString());
  1017. }
  1018. const JSONArray& projectTypeGuids = root["projectTypeGuids"].GetArray();
  1019. for (unsigned i = 0; i < projectTypeGuids.Size(); i++)
  1020. {
  1021. String guid = projectTypeGuids[i].GetString();
  1022. projectTypeGuids_.Push(ToString("{%s}", guid.CString()));
  1023. }
  1024. const JSONArray& importProjects = root["importProjects"].GetArray();
  1025. for (unsigned i = 0; i < importProjects.Size(); i++)
  1026. {
  1027. importProjects_.Push(importProjects[i].GetString());
  1028. }
  1029. const JSONArray& libraryProjectZips = root["libraryProjectZips"].GetArray();
  1030. for (unsigned i = 0; i < libraryProjectZips.Size(); i++)
  1031. {
  1032. String zipPath = libraryProjectZips[i].GetString();
  1033. ReplacePathStrings(zipPath);
  1034. libraryProjectZips_.Push(zipPath);
  1035. }
  1036. const JSONArray& transformFiles = root["transformFiles"].GetArray();
  1037. for (unsigned i = 0; i < transformFiles.Size(); i++)
  1038. {
  1039. String transformFile = transformFiles[i].GetString();
  1040. ReplacePathStrings(transformFile);
  1041. transformFiles_.Push(transformFile);
  1042. }
  1043. const JSONArray& sharedReferences = root["sharedReferences"].GetArray();
  1044. for (unsigned i = 0; i < sharedReferences.Size(); i++)
  1045. {
  1046. sharedReferences_.Push(sharedReferences[i].GetString());
  1047. }
  1048. targetFrameworkProfile_ = root["targetFrameworkProfile"].GetString();
  1049. // iOS
  1050. objcBindingApiDefinition_ = root["objcBindingApiDefinition"].GetString();
  1051. ReplacePathStrings(objcBindingApiDefinition_);
  1052. codesignEntitlements_ = root["codesignEntitlements"].GetString();
  1053. ReplacePathStrings(codesignEntitlements_);
  1054. infoPList_ = root["infoPList"].GetString();
  1055. ReplacePathStrings(infoPList_);
  1056. return true;
  1057. }
  1058. NETSolution::NETSolution(Context* context, NETProjectGen* projectGen, bool rewrite) : NETProjectBase(context, projectGen),
  1059. rewriteSolution_(rewrite)
  1060. {
  1061. }
  1062. NETSolution::~NETSolution()
  1063. {
  1064. }
  1065. bool NETSolution::Generate()
  1066. {
  1067. String slnPath = outputPath_ + name_ + ".sln";
  1068. GenerateSolution(slnPath);
  1069. return true;
  1070. }
  1071. void NETSolution::GenerateSolution(const String &slnPath)
  1072. {
  1073. String source = "Microsoft Visual Studio Solution File, Format Version 12.00\n";
  1074. source += "# Visual Studio 14\n";
  1075. source += "VisualStudioVersion = 14.0.25420.1\n";
  1076. source += "MinimumVisualStudioVersion = 10.0.40219.1\n";
  1077. solutionGUID_ = projectGen_->GenerateUUID();
  1078. PODVector<NETCSProject*> depends;
  1079. const Vector<SharedPtr<NETCSProject>>& projects = projectGen_->GetCSProjects();
  1080. for (unsigned i = 0; i < projects.Size(); i++)
  1081. {
  1082. NETCSProject* p = projects.At(i);
  1083. const String& projectName = p->GetName();
  1084. const String& projectGUID = p->GetProjectGUID();
  1085. String CSharpProjectGUID = "FAE04EC0-301F-11D3-BF4B-00C04F79EFBC";
  1086. String ext = "csproj";
  1087. if (p->outputType_ == "Shared")
  1088. {
  1089. CSharpProjectGUID = "D954291E-2A0B-460D-934E-DC6B0785DB48";
  1090. ext = "shproj";
  1091. }
  1092. source += ToString("Project(\"{%s}\") = \"%s\", \"%s\\%s.%s\", \"{%s}\"\n",
  1093. CSharpProjectGUID.CString(), projectName.CString(), projectName.CString(),
  1094. projectName.CString(), ext.CString(), projectGUID.CString());
  1095. projectGen_->GetCSProjectDependencies(p, depends);
  1096. if (depends.Size())
  1097. {
  1098. source += "\tProjectSection(ProjectDependencies) = postProject\n";
  1099. for (unsigned j = 0; j < depends.Size(); j++)
  1100. {
  1101. source += ToString("\t{%s} = {%s}\n",
  1102. depends[j]->GetProjectGUID().CString(), depends[j]->GetProjectGUID().CString());
  1103. }
  1104. source += "\tEndProjectSection\n";
  1105. }
  1106. source += "EndProject\n";
  1107. }
  1108. source += "Global\n";
  1109. // SharedMSBuildProjectFiles
  1110. source += " GlobalSection(SharedMSBuildProjectFiles) = preSolution\n";
  1111. for (unsigned i = 0; i < projects.Size(); i++)
  1112. {
  1113. NETCSProject* p = projects.At(i);
  1114. if (p->outputType_ == "Shared")
  1115. {
  1116. for (unsigned j = 0; j < projects.Size(); j++)
  1117. {
  1118. NETCSProject* p2 = projects.At(j);
  1119. if (p == p2)
  1120. {
  1121. source += ToString(" %s\\%s.projitems*{%s}*SharedItemsImports = 13\n", p->name_.CString(), p->name_.CString(), p->projectGuid_.CString());
  1122. }
  1123. else
  1124. {
  1125. if (p2->sharedReferences_.Contains(p->name_))
  1126. {
  1127. source += ToString(" %s\\%s.projitems*{%s}*SharedItemsImports = 4\n", p->name_.CString(), p->name_.CString(), p2->projectGuid_.CString());
  1128. }
  1129. }
  1130. }
  1131. }
  1132. }
  1133. source += " EndGlobalSection\n";
  1134. source += " GlobalSection(SolutionConfigurationPlatforms) = preSolution\n";
  1135. source += " Debug|Any CPU = Debug|Any CPU\n";
  1136. source += " Release|Any CPU = Release|Any CPU\n";
  1137. source += " Debug|iPhone = Debug|iPhone\n";
  1138. source += " Release|iPhone = Release|iPhone\n";
  1139. source += " EndGlobalSection\n";
  1140. source += " GlobalSection(ProjectConfigurationPlatforms) = postSolution\n";
  1141. for (unsigned i = 0; i < projects.Size(); i++)
  1142. {
  1143. NETCSProject* p = projects.At(i);
  1144. if (p->outputType_ == "Shared")
  1145. continue;
  1146. String cpu = "Any CPU";
  1147. if (p->GetIsPlayerApp() && p->SupportsPlatform("ios"))
  1148. cpu = "iPhone";
  1149. source += ToString(" {%s}.Debug|%s.ActiveCfg = Debug|%s\n", p->GetProjectGUID().CString(), cpu.CString(), cpu.CString());
  1150. source += ToString(" {%s}.Debug|%s.Build.0 = Debug|%s\n", p->GetProjectGUID().CString(), cpu.CString(), cpu.CString());
  1151. source += ToString(" {%s}.Release|%s.ActiveCfg = Release|%s\n", p->GetProjectGUID().CString(), cpu.CString(), cpu.CString());
  1152. source += ToString(" {%s}.Release|%s.Build.0 = Release|%s\n", p->GetProjectGUID().CString(), cpu.CString(), cpu.CString());
  1153. if (cpu != "iPhone" && (p->SupportsPlatform("ios", false)))
  1154. {
  1155. source += ToString(" {%s}.Debug|iPhone.ActiveCfg = Debug|Any CPU\n", p->GetProjectGUID().CString());
  1156. source += ToString(" {%s}.Debug|iPhone.Build.0 = Debug|Any CPU\n", p->GetProjectGUID().CString());
  1157. source += ToString(" {%s}.Release|iPhone.ActiveCfg = Release|Any CPU\n", p->GetProjectGUID().CString());
  1158. source += ToString(" {%s}.Release|iPhone.Build.0 = Release|Any CPU\n", p->GetProjectGUID().CString());
  1159. }
  1160. }
  1161. source += " EndGlobalSection\n";
  1162. source += "EndGlobal\n";
  1163. if (!rewriteSolution_)
  1164. {
  1165. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  1166. if (fileSystem->Exists(slnPath))
  1167. return;
  1168. }
  1169. SharedPtr<File> output(new File(context_, GetSanitizedPath(slnPath), FILE_WRITE));
  1170. output->Write(source.CString(), source.Length());
  1171. output->Close();
  1172. }
  1173. bool NETSolution::Load(const JSONValue& root)
  1174. {
  1175. FileSystem* fs = GetSubsystem<FileSystem>();
  1176. name_ = root["name"].GetString();
  1177. outputPath_ = AddTrailingSlash(root["outputPath"].GetString());
  1178. ReplacePathStrings(outputPath_);
  1179. // TODO: use poco mkdirs
  1180. if (!fs->DirExists(outputPath_))
  1181. fs->CreateDirsRecursive(outputPath_);
  1182. return true;
  1183. }
  1184. bool NETSolution::RegisterPackage(const String& package)
  1185. {
  1186. if (packages_.Find(package) != packages_.End())
  1187. return false;
  1188. packages_.Push(package);
  1189. return true;
  1190. }
  1191. NETProjectGen::NETProjectGen(Context* context) : Object(context),
  1192. rewriteSolution_(false)
  1193. {
  1194. }
  1195. NETProjectGen::~NETProjectGen()
  1196. {
  1197. }
  1198. NETCSProject* NETProjectGen::GetCSProjectByName(const String & name)
  1199. {
  1200. for (unsigned i = 0; i < projects_.Size(); i++)
  1201. {
  1202. if (projects_[i]->GetName() == name)
  1203. return projects_[i];
  1204. }
  1205. return nullptr;
  1206. }
  1207. bool NETProjectGen::GetCSProjectDependencies(NETCSProject* source, PODVector<NETCSProject*>& depends) const
  1208. {
  1209. depends.Clear();
  1210. const Vector<String>& references = source->GetReferences();
  1211. for (unsigned i = 0; i < projects_.Size(); i++)
  1212. {
  1213. NETCSProject* pdepend = projects_.At(i);
  1214. if (source == pdepend)
  1215. continue;
  1216. for (unsigned j = 0; j < references.Size(); j++)
  1217. {
  1218. if (pdepend->GetName() == references[j])
  1219. {
  1220. depends.Push(pdepend);
  1221. }
  1222. }
  1223. }
  1224. return depends.Size() != 0;
  1225. }
  1226. bool NETProjectGen::Generate()
  1227. {
  1228. solution_->Generate();
  1229. for (unsigned i = 0; i < projects_.Size(); i++)
  1230. {
  1231. if (!projects_[i]->Generate())
  1232. return false;
  1233. }
  1234. return true;
  1235. }
  1236. void NETProjectGen::SetRewriteSolution(bool rewrite)
  1237. {
  1238. rewriteSolution_ = rewrite;
  1239. if (solution_.NotNull())
  1240. solution_->SetRewriteSolution(rewrite);
  1241. }
  1242. bool NETProjectGen::IncludeProjectOnPlatform(const JSONValue& projectRoot, const String& platform)
  1243. {
  1244. const JSONArray& platforms = projectRoot["platforms"].GetArray();
  1245. if (!platforms.Size())
  1246. return true; // all platforms
  1247. String scriptPlatform = platform.ToLower();
  1248. for (unsigned i = 0; i < platforms.Size(); i++)
  1249. {
  1250. String platform = platforms[i].GetString().ToLower();
  1251. if (platform == "desktop")
  1252. {
  1253. if (scriptPlatform == "windows" || scriptPlatform == "macosx" || scriptPlatform == "linux")
  1254. return true;
  1255. return false;
  1256. }
  1257. if (platform == "android" && scriptPlatform != "android")
  1258. return false;
  1259. }
  1260. return true;
  1261. }
  1262. bool NETProjectGen::LoadProject(const JSONValue &root)
  1263. {
  1264. solution_ = new NETSolution(context_, this, rewriteSolution_);
  1265. solution_->Load(root["solution"]);
  1266. const JSONValue& jprojects = root["projects"];
  1267. if (!jprojects.IsArray() || !jprojects.Size())
  1268. return false;
  1269. for (unsigned i = 0; i < jprojects.Size(); i++)
  1270. {
  1271. const JSONValue& jproject = jprojects[i];
  1272. if (!jproject.IsObject())
  1273. return false;
  1274. JSONArray platforms = jproject["platforms"].GetArray();
  1275. if (platforms.Size())
  1276. {
  1277. bool found = false;
  1278. for (unsigned j = 0; j < platforms.Size(); j++)
  1279. {
  1280. if (GetSupportsPlatform(platforms[j].GetString()))
  1281. {
  1282. found = true;
  1283. break;
  1284. }
  1285. }
  1286. if (!found)
  1287. {
  1288. continue;
  1289. }
  1290. }
  1291. // HACK! Do not generate AtomicNETService in the AtomicProject solution
  1292. if (jproject["name"].GetString() == "AtomicNETService" && atomicProjectPath_.Length())
  1293. {
  1294. continue;
  1295. }
  1296. SharedPtr<NETCSProject> csProject(new NETCSProject(context_, this));
  1297. if (!csProject->Load(jproject))
  1298. return false;
  1299. projects_.Push(csProject);
  1300. }
  1301. return true;
  1302. }
  1303. bool NETProjectGen::LoadJSONProject(const String& jsonProjectPath)
  1304. {
  1305. SharedPtr<File> file(new File(context_));
  1306. if (!file->Open(GetSanitizedPath(jsonProjectPath)))
  1307. return false;
  1308. String json;
  1309. file->ReadText(json);
  1310. JSONValue jvalue;
  1311. if (!JSONFile::ParseJSON(json, jvalue))
  1312. return false;
  1313. return LoadProject(jvalue);
  1314. }
  1315. \
  1316. bool NETProjectGen::LoadAtomicProject(const String& atomicProjectPath)
  1317. {
  1318. ToolEnvironment* tenv = GetSubsystem<ToolEnvironment>();
  1319. ToolSystem* tsystem = GetSubsystem<ToolSystem>();
  1320. String pathname, filename, ext;
  1321. SplitPath(atomicProjectPath, pathname, filename, ext);
  1322. if (ext == ".atomic")
  1323. {
  1324. atomicProjectPath_ = AddTrailingSlash(pathname);
  1325. }
  1326. else
  1327. {
  1328. atomicProjectPath_ = AddTrailingSlash(atomicProjectPath);
  1329. }
  1330. // Do we have a loaded project?
  1331. if (Project* project = tsystem->GetProject())
  1332. {
  1333. // If so, use loaded project settings
  1334. projectSettings_ = project->GetProjectSettings();
  1335. }
  1336. else
  1337. {
  1338. // Nope, load them up
  1339. projectSettings_ = SharedPtr<ProjectSettings>(new ProjectSettings(context_));
  1340. projectSettings_->Load(atomicProjectPath_ + "Settings/Project.json");
  1341. }
  1342. #ifdef ATOMIC_DEV_BUILD
  1343. JSONValue netJSON;
  1344. SharedPtr<File> netJSONFile(new File(context_));
  1345. String atomicNETProject = tenv->GetRootSourceDir() + "Script/AtomicNET/AtomicNETProject.json";
  1346. if (!netJSONFile->Open(GetSanitizedPath(atomicNETProject)))
  1347. return false;
  1348. String netJSONString;
  1349. netJSONFile->ReadText(netJSONString);
  1350. if (!JSONFile::ParseJSON(netJSONString, netJSON))
  1351. return false;
  1352. #endif
  1353. AtomicNETCopyAssemblies(context_, atomicProjectPath_ + "AtomicNET/Lib/");
  1354. #ifdef ATOMIC_DEV_BUILD
  1355. String projectPath = tenv->GetRootSourceDir() + "Script/AtomicNET/AtomicProject.json";
  1356. #else
  1357. String projectPath = tenv->GetAtomicNETRootDir() + "Build/Projects/AtomicProject.json";
  1358. #endif
  1359. SharedPtr<File> file(new File(context_));
  1360. if (!file->Open(GetSanitizedPath(projectPath)))
  1361. return false;
  1362. String json;
  1363. file->ReadText(json);
  1364. json.Replace("$ATOMIC_PROJECT_NAME$", projectSettings_->GetName());
  1365. JSONValue jvalue;
  1366. if (!JSONFile::ParseJSON(json, jvalue))
  1367. return false;
  1368. #ifdef ATOMIC_DEV_BUILD
  1369. // patch projects
  1370. JSONArray netProjects = netJSON["projects"].GetArray();
  1371. JSONArray projects = jvalue["projects"].GetArray();
  1372. for (unsigned i = 0; i < projects.Size(); i++)
  1373. {
  1374. netProjects.Push(JSONValue(projects[i].GetObject()));
  1375. }
  1376. jvalue["projects"] = netProjects;
  1377. return LoadProject(jvalue);
  1378. #else
  1379. return LoadProject(jvalue);
  1380. #endif
  1381. }
  1382. void NETProjectGen::SetSupportedPlatforms(const StringVector& platforms)
  1383. {
  1384. projectSettings_ = SharedPtr<ProjectSettings>(new ProjectSettings(context_));
  1385. for (unsigned i = 0; i < platforms.Size(); i++)
  1386. {
  1387. projectSettings_->AddSupportedPlatform(platforms[i]);
  1388. }
  1389. }
  1390. bool NETProjectGen::GetSupportsPlatform(const String& platform) const
  1391. {
  1392. // If no project platform settings are loaded, always supports
  1393. if (projectSettings_.Null())
  1394. {
  1395. return true;
  1396. }
  1397. return projectSettings_->GetSupportsPlatform(platform);
  1398. }
  1399. bool NETProjectGen::GetRequiresNuGet()
  1400. {
  1401. if (solution_.Null())
  1402. {
  1403. ATOMIC_LOGERROR("NETProjectGen::GetRequiresNuGet() - called without a solution loaded");
  1404. return false;
  1405. }
  1406. return solution_->GetPackages().Size() != 0;
  1407. }
  1408. String NETProjectGen::GenerateUUID()
  1409. {
  1410. Poco::UUIDGenerator& generator = Poco::UUIDGenerator::defaultGenerator();
  1411. Poco::UUID uuid(generator.create()); // time based
  1412. return String(uuid.toString().c_str()).ToUpper();
  1413. }
  1414. }