简体   繁体   中英

Start a process from another project for integration testing in C#

I have a .NET Framework project that requires running a built console application from a .NET Core project in the same solution.

Take the example file structure:

  • Test/bin/Debug/Test.exe
  • Service/bin/Debug/netcoreapp2.2/Service.dll

The current approach involves starting a new process , similar to the following:

dotnet run ../../../Service/bin/Debug/netcoreapp2.2/Service.dll

I am fairly new to .NET, and so unsure if the following ideas are possible:

  • Modifying the path when running the Test application so that I can start the Service process with dotnet run Service.dll .
  • Getting the Test project to copy the Service build files into the Test build folder.

For bonus points, if/when the Framework project is upgraded to Core, is it possible to start a Core application process by using it in another application?

Edit:

For clarification, I'm hoping to avoid using that hard-coded relative path to build output folder, since it changes between Framework and Core and different versions of Core. My hope is to find a built-in variable or functionality to get the build location of another project (even if I need to hard-code the Debug/Release part).

For example (excuse the pseudocode):

using Service;
var path = getPathToDebugBuildFolder(Service);
startProcess(Path.Join(path, "Service.dll"));

If you right click your project in Visual Studio you can define your Pre- and PostBuild Tasks (Build Events).

And yes.. if you are using .NET Core for both applications then you can Add a reference to your class library / console application and use the public types.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM