Преглед изворни кода

Create .user file for Atomic C# Project with settings for running from VS2015

Josh Engebretson пре 9 година
родитељ
комит
cbdb21cc15

+ 48 - 2
Source/ToolCore/NETTools/NETProjectGen.cpp

@@ -369,7 +369,9 @@ namespace ToolCore
 
     bool NETCSProject::Generate()
     {
+        FileSystem* fileSystem = GetSubsystem<FileSystem>();
         NETSolution* solution = projectGen_->GetSolution();
+        ToolEnvironment* tenv = GetSubsystem<ToolEnvironment>();
 
         projectPath_ = solution->GetOutputPath() + name_ + "/";
 
@@ -401,13 +403,56 @@ namespace ToolCore
 
         project.CreateChild("Import").SetAttribute("Project", "$(MSBuildToolsPath)\\Microsoft.CSharp.targets");
 
-        if (name_ == "AtomicProject")
+        Project* atomicProject = projectGen_->GetAtomicProject();
+
+        if (atomicProject)
         {
             XMLElement afterBuild = project.CreateChild("Target");
             afterBuild.SetAttribute("Name", "AfterBuild");
             XMLElement copy = afterBuild.CreateChild("Copy");
             copy.SetAttribute("SourceFiles", "$(TargetPath)");
             copy.SetAttribute("DestinationFolder", projectPath_ + "../../../Resources/");
+
+            // Create the AtomicProject.csproj.user file if it doesn't exist
+            String userSettingsFilename = projectPath_ + name_ + ".csproj.user";
+            if (!fileSystem->FileExists(userSettingsFilename))
+            {
+                SharedPtr<XMLFile> userSettings(new XMLFile(context_));
+
+                XMLElement project = userSettings->CreateRoot("Project");
+                
+                //XMLElement xml = userRoot.CreateChild("?xml");
+                //xml.SetAttribute("version", "1.0");
+                //xml.SetAttribute("encoding", "utf-8");
+
+                project.SetAttribute("ToolsVersion", "14.0");
+                project.SetAttribute("xmlns", "http://schemas.microsoft.com/developer/msbuild/2003");
+
+                StringVector configs;
+                configs.Push("Debug");
+                configs.Push("Release");
+
+                for (unsigned i = 0; i < configs.Size(); i++)
+                {
+                    String cfg = configs[i];
+
+                    XMLElement propertyGroup = project.CreateChild("PropertyGroup");
+                    propertyGroup.SetAttribute("Condition", ToString("'$(Configuration)|$(Platform)' == '%s|AnyCPU'", cfg.CString()));
+
+                    String playerBin = tenv->GetAtomicNETRootDir() + cfg + "/AtomicPlayer.exe";
+                    propertyGroup.CreateChild("StartAction").SetValue("Program");                    
+                    propertyGroup.CreateChild("StartProgram").SetValue(playerBin );
+                    propertyGroup.CreateChild("StartArguments").SetValue(ToString("--project %s", atomicProject->GetProjectPath().CString()));
+                    
+                }
+
+                String userSettingsSource = userSettings->ToString();
+                SharedPtr<File> output(new File(context_, userSettingsFilename, FILE_WRITE));
+                output->Write(userSettingsSource.CString(), userSettingsSource.Length());
+                output->Close();
+
+            }
+            
         }
 
         String projectSource = xmlFile_->ToString();
@@ -700,8 +745,9 @@ namespace ToolCore
         FileSystem* fileSystem = GetSubsystem<FileSystem>();
         ToolEnvironment* tenv = GetSubsystem<ToolEnvironment>();
 
-        JSONValue root;
+        atomicProject_ = project;
 
+        JSONValue root;
         JSONValue solution;
 
         solution["name"] = "AtomicProject";

+ 3 - 0
Source/ToolCore/NETTools/NETProjectGen.h

@@ -152,6 +152,8 @@ namespace ToolCore
 
         const Vector<SharedPtr<NETCSProject>>& GetCSProjects() { return projects_; }
 
+        Project* GetAtomicProject() const { return atomicProject_;  }
+
         NETCSProject* GetCSProjectByName(const String& name);
 
         bool GetCSProjectDependencies(NETCSProject * source, PODVector<NETCSProject*>& depends) const;
@@ -173,6 +175,7 @@ namespace ToolCore
 
         String scriptPlatform_;
 
+        SharedPtr<Project> atomicProject_;
         SharedPtr<NETSolution> solution_;
         Vector<SharedPtr<NETCSProject>> projects_;
 

+ 1 - 1
Source/ToolCore/ToolEnvironment.cpp

@@ -168,8 +168,8 @@ void ToolEnvironment::SetRootSourceDir(const String& sourceDir)
 
     atomicNETNuGetBinary_ = ToString("%sBuild/Managed/nuget/nuget.exe", rootSourceDir_.CString());
 
+    atomicNETRootDir_ = rootSourceDir_ + "Artifacts/AtomicNET/";
     atomicNETCoreAssemblyDir_ = rootSourceDir_ + "Artifacts/AtomicNET/" + config + "/";
-
     atomicNETManagedPlayerBinary_ = atomicNETCoreAssemblyDir_ + "AtomicPlayer.exe";
 
 }

+ 2 - 0
Source/ToolCore/ToolEnvironment.h

@@ -81,6 +81,7 @@ public:
 
     // AtomicNET
 
+    const String& GetAtomicNETRootDir() { return atomicNETRootDir_; }
     const String& GetAtomicNETCoreAssemblyDir() { return atomicNETCoreAssemblyDir_; }
     const String& GetAtomicNETNuGetBinary() { return atomicNETNuGetBinary_; }
     const String& GetAtomicNETManagedPlayerBinary() { return atomicNETManagedPlayerBinary_; }
@@ -140,6 +141,7 @@ private:
     String devConfigFilename_;
 
     // AtomicNET
+    String atomicNETRootDir_;
     String atomicNETCoreAssemblyDir_;
     String atomicNETNuGetBinary_;
     String atomicNETManagedPlayerBinary_;