NETProjectGen.cpp 64 KB

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