[英]Visual Studio Solution(.sln) / C#: Start a project with another project's dll as parameter
is it possible to run a project with an argument of a dll from another project?是否可以使用来自另一个项目的 dll 的参数运行一个项目?
My project structure and dependencies look like this我的项目结构和依赖项如下所示
As you can see there are no direct dependencies between a mod and the game implementation directly.如您所见,mod 和游戏实现之间没有直接的依赖关系。
When I click on Debug -> Start New Instance
, F5
or use the button (当我点击
Debug -> Start New Instance
, F5
或使用按钮( ) I want to run
./ExampleGameInEngineA.exe GameModC.dll
. ) 我想运行
./ExampleGameInEngineA.exe GameModC.dll
。
I know that you can set an Executable
in the project settings我知道你可以在项目设置中设置一个
Executable
But I am looking for a more generic way that is automatically compiling ExampleGameInEngineA
and putting it in the same directory as GameModC
.但我正在寻找一种更通用的方法,即自动编译
ExampleGameInEngineA
并将其放在与GameModC
相同的目录中。 Hardcoded directory paths are also not great (tho I could use relative paths for this).硬编码的目录路径也不是很好(我可以为此使用相对路径)。
For testing purposes we can safely ignore GameInEngineB
but I still don't want any hard references to GameInEngineA
.出于测试目的,我们可以放心地忽略
GameInEngineB
但我仍然不希望对GameInEngineA
进行任何硬引用。
Okay, I kinda solved it by myself by using a PreBuild-Event-Target:好的,我通过使用 PreBuild-Event-Target 自己解决了这个问题:
GameModC.csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<RunPostBuildEvent>OnOutputUpdated</RunPostBuildEvent>
</PropertyGroup>
<Target Name="PreBuild" BeforeTargets="PreBuildEvent" Condition="">
<MSBuild Projects="$(SolutionDir)ExampleGameInEngineA\ExampleGameInEngineA.csproj..." />
<ItemGroup>
<GameEngineAOutputFolder Include="$(SolutionDir)ExampleGameInEngineA\$(OutDir)*.*" />
</ItemGroup>
<Copy SourceFiles="@(GameEngineAOutputFolder)" DestinationFolder="$(OutDir)" SkipUnchangedFiles="false" />
</Target>
<ItemGroup>
<ProjectReference Include="..\GameApi\GameModdingApi.csproj" />
</ItemGroup>
</Project>
GameInEngineA.csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\GameApi\GameModdingApi.csproj" />
</ItemGroup>
</Project>
Please note the AppendTargetFrameworkToOutputPath
to remove the netcoreapp3.1
or netstandard2.1
.请注意
AppendTargetFrameworkToOutputPath
以删除netcoreapp3.1
或netstandard2.1
。
But there are still problems with the solution:但是解决方案仍然存在问题:
ExampleGameInEngineA
(manual rebuild required)ExampleGameInEngineA
中所做的更改(需要手动重建)Condition
when to add ExampleGameInEngineA
is always met (because I have no good idea for a condition)ExampleGameInEngineA
的Condition
(因为我对条件没有好主意) I am still open for better solutions.我仍然愿意寻求更好的解决方案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.