简体   繁体   English

Visual Studio Solution(.sln) / C#:以另一个项目的 dll 作为参数启动一个项目

[英]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 InstanceF5或使用按钮( 在此处输入图像描述 ) 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.1netstandard2.1

But there are still problems with the solution:但是解决方案仍然存在问题:

  • It does not recognize changes made in ExampleGameInEngineA (manual rebuild required)它无法识别在ExampleGameInEngineA中所做的更改(需要手动重建)
  • The Condition when to add ExampleGameInEngineA is always met (because I have no good idea for a condition)总是满足添加ExampleGameInEngineACondition (因为我对条件没有好主意)

I am still open for better solutions.我仍然愿意寻求更好的解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Visual Studio C#解决方案中将DLL引用替换为Project refs以获取项目依赖性 - Replace DLL refs with Project refs for project dependencies in Visual Studio C# solution c# 项目中没有 .sln 文件 - no .sln file in c# project 如何从Visual Studio C#中的不同解决方案启动另一个项目? - How to launch another project from a different solution in Visual Studio C#? 如何从C#项目的构建事件中访问Visual Studio解决方案级平台? - How can you access the Visual Studio solution level platform from a C# project's build event? 将项目从OutSystems转换为C#Visual Studio解决方案 - Convert a project from OutSystems to C# Visual Studio solution 如何确定C#Visual Studio项目生成的可执行文件和DLL? - How do you determine what executable and DLL’s a C# Visual Studio project produces? 在Visual Studio C#项目中包含Oracle.DataAccess.dll - Include Oracle.DataAccess.dll in Visual Studio C# Project 将 dll 引用添加到 github 上可见的 Visual Studio c# 项目 - Adding dll reference to visual studio c# project visible on github 在Visual Studio 2010 C#项目中将.chm文件链接到.dll - Linking a .chm file to a .dll in Visual Studio 2010 C# Project Visual Studio C#.dll与项目引用 - Visual Studio C# .dll vs. project referencing
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM