My ASP application in VB has many modules that I'd like to share with a WinForms VB application. But the VB.ASP modules have includes that won't be necessary, useful, or possible to include in the WinForms app. Can I use compiler directives to enable one file to work in both projects?
Asked
Active
Viewed 350 times
1
-
Do your INCLUDES in another module (file) and dont bring them into the VB app, only the ASP app. You can have multiple MODULE files and they are treated like they are just one file, but yet you can divide stuff up to have one MODULE in one project and another in some other project, or both in one. – Steve Oct 18 '13 at 19:07
2 Answers
1
check out this question: VB.NET Preprocessor Directives it shows how you can use preprocessor directives
so, basically you need to include your files into Winforms app and in these files add lines like this:
#IF MYDEFINEFORASPNET Then
require/import/define functions which are only for .net
#End if
#if MYDEFINEFORWINFORM Then
require/import/function for only win form
#End if
define generic functions
another way to achieve this - refactor your code to move generic parts into separate dll, which can be used for both projects without recompiling

Community
- 1
- 1

Iłya Bursov
- 23,342
- 4
- 33
- 57
-
I've looked at lots of information online already. But all the examples show CODE being changed, not IMPORTS. And none refer to how to distinguish between code being generated for ASP vs WinForms. – user212421 Oct 18 '13 at 18:21
-
you question about code being changed, not about import, updating answer – Iłya Bursov Oct 18 '13 at 18:24
0
Self defined values is indeed one way, but I think I have another.
The _MYTYPE compilation constant is managed by Visual Studio, and contains "Windows", "Console", "Web", and similar specifics. And I can enclose IMPORTS statements inside the #If like so:
#If _MYTYPE = "Web" Then
Imports System.Web.HttpRequest
#End If
Refactoring does appear to the required to do this, unfortunately. They probably won't let me do that.

user212421
- 97
- 7