Merge pull request #201 from SHADE-DP/SP3-6-c-scripting

References path for csproj generated file is now dynamically generated
This commit is contained in:
XiaoQiDigipen 2022-11-13 22:30:46 +08:00 committed by GitHub
commit 557a198367
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 18 additions and 10 deletions

View File

@ -238,8 +238,13 @@ namespace SHADE
void SHScriptEngine::GenerateScriptsCsProjFile(const std::filesystem::path& path) const void SHScriptEngine::GenerateScriptsCsProjFile(const std::filesystem::path& path) const
{ {
// Compute relative path
const std::filesystem::path EXE_DIR = std::filesystem::current_path();
const std::filesystem::path MANAGED_DLL_DIR = EXE_DIR / "SHADE_Managed.dll";
const std::filesystem::path CS_DLL_DIR = EXE_DIR / "SHADE_CSharp.dll";
// Sample // Sample
static std::string_view FILE_CONTENTS = static std::string_view FILE_CONTENTS_BEGIN =
"<Project Sdk=\"Microsoft.NET.Sdk\">\n\ "<Project Sdk=\"Microsoft.NET.Sdk\">\n\
<PropertyGroup>\n\ <PropertyGroup>\n\
<TargetFramework>net5.0</TargetFramework>\n\ <TargetFramework>net5.0</TargetFramework>\n\
@ -269,14 +274,12 @@ namespace SHADE
<None Remove=\".gitmodules\" />\n\ <None Remove=\".gitmodules\" />\n\
</ItemGroup>\n\ </ItemGroup>\n\
<ItemGroup>\n\ <ItemGroup>\n\
<Reference Include=\"SHADE_Managed\">\n\ <Reference Include=\"SHADE_Managed\">\n";
<HintPath Condition=\"Exists('..\\..\\bin\\Debug\\SHADE_Managed.dll')\">..\\..\\bin\\Debug\\SHADE_Managed.dll</HintPath>\n\ static std::string_view FILE_CONTENTS_MID =
<HintPath Condition=\"Exists('..\\..\\bin\\Release\\SHADE_Managed.dll')\">..\\..\\bin\\Release\\SHADE_Managed.dll</HintPath>\n\ " </Reference>\n\
</Reference>\n\ <Reference Include=\"SHADE_CSharp\">\n";
<Reference Include=\"SHADE_CSharp\">\n\ static std::string_view FILE_CONTENTS_END =
<HintPath Condition=\"Exists('..\\..\\bin\\Debug\\SHADE_Managed.dll')\">..\\..\\bin\\Debug\\SHADE_CSharp.dll</HintPath>\n\ " </Reference>\n\
<HintPath Condition=\"Exists('..\\..\\bin\\Release\\SHADE_Managed.dll')\">..\\..\\bin\\Release\\SHADE_CSharp.dll</HintPath>\n\
</Reference>\n\
</ItemGroup>\n\ </ItemGroup>\n\
</Project>"; </Project>";
@ -286,7 +289,12 @@ namespace SHADE
throw std::runtime_error("Unable to create CsProj file!"); throw std::runtime_error("Unable to create CsProj file!");
// Fill the file // Fill the file
file << FILE_CONTENTS; const std::filesystem::path CSPROJ_DIR = path.parent_path();
file << FILE_CONTENTS_BEGIN
<< " <HintPath>" << std::filesystem::relative(MANAGED_DLL_DIR, CSPROJ_DIR).string() << "</HintPath>\n"
<< FILE_CONTENTS_MID
<< " <HintPath>" << std::filesystem::relative(CS_DLL_DIR, CSPROJ_DIR).string() << "</HintPath>\n"
<< FILE_CONTENTS_END;
// Close // Close
file.close(); file.close();