Double Reference Causing Issues in Intellisense

Viewed 98

First i explain our current project structure, then problem statement

I have a plugin project for CRM, and that project is referencing another service project. In order to deploy the project i am using ILMerge , so when plugin project compiled , it will contain all Service Project contract and models also.I have created unit test project also on the same solution, i have written test methods for Service Project , (by referring to Service Project) .All Test methods are working fine

Now we have changed our strategy to do the unit testing on plugin project instead of Service Project. So i remove the reference of service and added the reference of Plugins,All the unit test are still pass on run time. because on run time assembly internally contains service class attributes and methods.

But on editing the unit test, we lost the intellisense help from Visual Studio because we are not directly referring Service Project, if i try to refer service & plugin both, then getting compile time error saying that these classes exists via plugins.

Here i want to use intellisense to make better code, and don't want double reference issue also.

Can some one help on this

1 Answers

I too had this issue. Finally found a solution.

So you have assembly A, B and merge them into M' (A, B -> M). And then you have Test project where you use types from A,B,M.

  1. Reference any merged assemblies A, B via regular project reference.

  2. As for M assembly, I only reference the original M.dll that doesn't contain A, B types. This assembly is put into M/obj/$(ConfigurationName) folder. (Merged M' assembly is within bin folder)

    So when adding reference, don't add project reference, but browse to ../M/obj/Release/M.dll

  3. Open Test.csproj and find

    <Reference Include="M">
      <HintPath>..\M\obj\Release\M.dll</HintPath>
    </Reference>
    

    Replace HintPath with ..\M\obj\$(ConfigurationName)\M.dll

  4. Make sure you specify build order for solution so that Test depends on A,B,M

I also tried to Internalize A, B types when merging into M (public types become internal), but as you deploy to CRM, Proxy stuff (i.e. classes inherited from OrganizationRequset/Response that must be deserialized when using Execute method) must be public. Excluding these types from internalization brings back to duplicate type errors.

Another issue it solves if you only have merged M' referenced in test project. If you happen to use some interface in Test project that is defined within A and you happen to test C functionality that also uses this type... err, it just complains error CS0012: The type 'SomeType' is defined in an assembly that is not referenced. You must add a reference to assembly. I suspect that it is because in Test project you are actually using type from M' assembly and it is not equivalent to that interface from A used in C assembly.

Related