Programatically removing a reference???
-
I have some custom controls which contains a System.Windows.Forms.Label control. I would like to be able to swap out those label controls with a third party label control. What I would like to do is the following...
#if UsingThirdPartyControls namespace WindowsApplication4 { public class MyCustomLabel : ThirdPartyLabel { } } #else namespace WindowsApplication4 { public class MyCustomLabel : Label { } } #endif
Now I can use MyCustomLabel in my custom controls and based on the type of build (one build will have UsingThirdPartyControls defined and another will not). The problem is removing the reference to the third party controls. Is there a way I can programatically tell the C# compiler to remove the references to the third party assemblies. That way when I deploy my custom control the third party assemblies are not deployed because they are not required? Chris -
I have some custom controls which contains a System.Windows.Forms.Label control. I would like to be able to swap out those label controls with a third party label control. What I would like to do is the following...
#if UsingThirdPartyControls namespace WindowsApplication4 { public class MyCustomLabel : ThirdPartyLabel { } } #else namespace WindowsApplication4 { public class MyCustomLabel : Label { } } #endif
Now I can use MyCustomLabel in my custom controls and based on the type of build (one build will have UsingThirdPartyControls defined and another will not). The problem is removing the reference to the third party controls. Is there a way I can programatically tell the C# compiler to remove the references to the third party assemblies. That way when I deploy my custom control the third party assemblies are not deployed because they are not required? ChrisI never tried, but as of my understanding, The Solution file ( *.csProj ) contains the sections to add reference under ItemGroup tag these references are listed. This tag supports condition attribute. So you can write a custom task, which executes under target BeforeCoreGet and sets the condtion attribute of reference ItemGroup accordingly. Try to search for CustomTask for MSBuild, you found many pre built tasks contributed by communities.
Regards, Vythees Miles to go before sleep...
-
I never tried, but as of my understanding, The Solution file ( *.csProj ) contains the sections to add reference under ItemGroup tag these references are listed. This tag supports condition attribute. So you can write a custom task, which executes under target BeforeCoreGet and sets the condtion attribute of reference ItemGroup accordingly. Try to search for CustomTask for MSBuild, you found many pre built tasks contributed by communities.
Regards, Vythees Miles to go before sleep...
Wow thanks alot. I found this web site which shows that you can have a condition where if the build is set to a certain type then you can include or exclude references. Then in the build I can define something like UsingThirdPartyControls and in my code I can place #if UsingThirdPartyControls #endif. I think this could work. Thanks alot. Chris