References path for csproj generated file is now dynamically generated

This commit is contained in:
Kah Wei 2022-11-13 22:29:04 +08:00
parent e3d2515740
commit 73a5d5e4b9
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
{
// 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
static std::string_view FILE_CONTENTS =
static std::string_view FILE_CONTENTS_BEGIN =
"<Project Sdk=\"Microsoft.NET.Sdk\">\n\
<PropertyGroup>\n\
<TargetFramework>net5.0</TargetFramework>\n\
@ -269,14 +274,12 @@ namespace SHADE
<None Remove=\".gitmodules\" />\n\
</ItemGroup>\n\
<ItemGroup>\n\
<Reference Include=\"SHADE_Managed\">\n\
<HintPath Condition=\"Exists('..\\..\\bin\\Debug\\SHADE_Managed.dll')\">..\\..\\bin\\Debug\\SHADE_Managed.dll</HintPath>\n\
<HintPath Condition=\"Exists('..\\..\\bin\\Release\\SHADE_Managed.dll')\">..\\..\\bin\\Release\\SHADE_Managed.dll</HintPath>\n\
</Reference>\n\
<Reference Include=\"SHADE_CSharp\">\n\
<HintPath Condition=\"Exists('..\\..\\bin\\Debug\\SHADE_Managed.dll')\">..\\..\\bin\\Debug\\SHADE_CSharp.dll</HintPath>\n\
<HintPath Condition=\"Exists('..\\..\\bin\\Release\\SHADE_Managed.dll')\">..\\..\\bin\\Release\\SHADE_CSharp.dll</HintPath>\n\
</Reference>\n\
<Reference Include=\"SHADE_Managed\">\n";
static std::string_view FILE_CONTENTS_MID =
" </Reference>\n\
<Reference Include=\"SHADE_CSharp\">\n";
static std::string_view FILE_CONTENTS_END =
" </Reference>\n\
</ItemGroup>\n\
</Project>";
@ -286,7 +289,12 @@ namespace SHADE
throw std::runtime_error("Unable to create CsProj 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
file.close();