c# - Using C#, how can I pass an argument from one project to another
问题描述
I want to debug my MainApp which is a .NET console application which should receive argument from the user. I can right click MainApp>properties>debug and add the required parameter there but this means setting them manually for each test.
I created another project (TESTER) to test MainApp. I added a reference to MainApp in TESTER. How do I call Main, in MainApp from TESTER and pass it arguments programmatically?
MainApp looks like this:
namespace MainApp
{
public class GetData
{
public static void Main(string[] args)
However, from TESTER I can't call Main
var bmsDb = new MainApp.GetData.Main
is not vailable;
解决方案
如果您知道哪个类MainApp
包含 Main 方法(并且该类是公共的),则可以从测试项目中调用它并将参数传递给它,就像调用任何其他静态方法一样。
测试程序集中的 Main 方法应如下所示:
public static void Main() {
var arguments = new string[] {"arg1", "arg2"};
MainApp.GetData.Main(arguments);
}
推荐阅读
- c++ - OpenCL:clSetKernelArg 中的 CL_INVALID_ARG_SIZE
- python - Python中常量'e'的奇怪行为
- c# - 如何根据 LINQ 中的另一个字段动态选择字段?
- r - 如何从 R 中的泰勒图中提取 cRMSE、StD 和 CC?
- c++ - 存储具有可变数量参数的 boost::function 对象
- python - 如何在数据框中随机分配值
- alexa - 在 ElicitSlot 模式下,Alexa 如何识别停止/取消意图
- c# - 在 Visual Studio C# 中将数据添加到现有 Excel 工作表
- python - Django - Python - URL 与这些都不匹配
- python - 替换方法不从熊猫数据框列中删除字符串