如何根据当前项目构建调用另一个依赖项的函数的依赖项?

时间:2023-01-25 11:34:47

Explained: I have a huge project that is built over a solid framework where functions that has to connect to the database works differently depending on a few conditions (in simple terms we can just say its a true/false boolean). In simple terms, when it access the DB, it access either as web service or a direct mysql connection.

解释:我有一个庞大的项目构建在一个可靠的框架上,其中必须连接到数据库的函数根据一些条件(在简单的术语中我们可以说它的真/假布尔值)有不同的工作方式。简单来说,当它访问数据库时,它可以作为Web服务或直接的mysql连接进行访问。

Now I am starting to create a Xamarin project (android) and I want to import this framework, however, Xamarin doesn't support mysql... although the framework can make calls to a webservice to get the mysql data, the fact that the mysql code is there it stops my xamarin project from building. I cant even use "#if" because there is still a reference to the mysql dll. How would I go about to split my class dll file so that for this android project doesn't load the mysql dll, just part of the function that calls the web service? Example of how the function looks like:

现在我开始创建一个Xamarin项目(android)并且我想导入这个框架,但是,Xamarin不支持mysql ...虽然框架可以调用webservice来获取mysql数据,事实上mysql代码在那里阻止我的xamarin项目建设。我甚至不能使用“#if”,因为仍然有对mysql dll的引用。我将如何分割我的类dll文件,以便这个android项目不加载mysql DLL,只是调用Web服务的函数的一部分?该函数的示例如下:

public static void InsertStuff(object stuff, bool useDirectMysql)
{
    if (useDirectMysql)//I would like that this part only appears/works if its not the xamarin project, however, i can't use #if as the framework dll still has a reference to the mysql dll
    {
        //MySqlConnection connection = new MySqlConnection....
        //insert stuff
    }
    else
    {
        //Insert stuff with a web service function.. (compatible with xamarin)
    }
}

2 个解决方案

#1


1  

The pattern for implementing platform specific features goes like this:

实现平台特定功能的模式如下:

  • Create an interface in your shared project that has a method InsertStuff.

    在共享项目中创建一个具有InsertStuff方法的接口。

  • Inject the dependency using DI.

    使用DI注入依赖项。

  • Implement the interface in each of the platform projects accordingly.

    相应地在每个平台项目中实现接口。

#2


0  

Zdravko provided a nice work around

Zdravko提供了一个很好的工作

However, I accomplished what I wanted by literally compiler commenting every single usage or reference of properties, functions, objects and references ("using ...") from the framework. So although it has references to the .dll files in the references part of the project, Visual Studio seems to not compile/emb those dlls that are not used.

但是,我完成了我想要的,从字面上编译器评论框架中的属性,函数,对象和引用(“using ...”)的每一个用法或引用。因此虽然它引用了项目引用部分中的.dll文件,但Visual Studio似乎没有编译/嵌入那些未使用的dll。

My ultimate solution was:

我的终极解决方案是:

1-Create 2 build configurations, one for the xamarin project and the framework and another for my normal windows programs and the framework.

1 - 创建2个构建配置,一个用于xamarin项目和框架,另一个用于我的普通Windows程序和框架。

2-Comment everything not compatible with mobile xamarin (but still keeping the reference on the project)

2 - 评论一切与移动设备不兼容(但仍保留项目参考)

3-Created a compiler variable like A. When I want to compile my xamarin project, i select the build configuration that just allows the framework and the xamarin, put the A in my framework dll and it compiles.

3 - 创建一个像A这样的编译器变量。当我想编译我的xamarin项目时,我选择只允许框架和xamarin的构建配置,将A放在我的框架dll中并编译。

4-Change configuration and remote the A when building normal c#/c++/etc programs.

4 - 在构建正常的c#/ c ++ / etc程序时更改配置并远程A。

Everything is on the same VS solution.

一切都在同一个VS解决方案上。

#1


1  

The pattern for implementing platform specific features goes like this:

实现平台特定功能的模式如下:

  • Create an interface in your shared project that has a method InsertStuff.

    在共享项目中创建一个具有InsertStuff方法的接口。

  • Inject the dependency using DI.

    使用DI注入依赖项。

  • Implement the interface in each of the platform projects accordingly.

    相应地在每个平台项目中实现接口。

#2


0  

Zdravko provided a nice work around

Zdravko提供了一个很好的工作

However, I accomplished what I wanted by literally compiler commenting every single usage or reference of properties, functions, objects and references ("using ...") from the framework. So although it has references to the .dll files in the references part of the project, Visual Studio seems to not compile/emb those dlls that are not used.

但是,我完成了我想要的,从字面上编译器评论框架中的属性,函数,对象和引用(“using ...”)的每一个用法或引用。因此虽然它引用了项目引用部分中的.dll文件,但Visual Studio似乎没有编译/嵌入那些未使用的dll。

My ultimate solution was:

我的终极解决方案是:

1-Create 2 build configurations, one for the xamarin project and the framework and another for my normal windows programs and the framework.

1 - 创建2个构建配置,一个用于xamarin项目和框架,另一个用于我的普通Windows程序和框架。

2-Comment everything not compatible with mobile xamarin (but still keeping the reference on the project)

2 - 评论一切与移动设备不兼容(但仍保留项目参考)

3-Created a compiler variable like A. When I want to compile my xamarin project, i select the build configuration that just allows the framework and the xamarin, put the A in my framework dll and it compiles.

3 - 创建一个像A这样的编译器变量。当我想编译我的xamarin项目时,我选择只允许框架和xamarin的构建配置,将A放在我的框架dll中并编译。

4-Change configuration and remote the A when building normal c#/c++/etc programs.

4 - 在构建正常的c#/ c ++ / etc程序时更改配置并远程A。

Everything is on the same VS solution.

一切都在同一个VS解决方案上。