none
VS 2019 two compilation questions

    Question

  • Cuestion 1.- In VS 2017 I have a class called "Common" that includes various useful functions to the rest of the classes.

    If I extract one of the functions and include it in a new class, when I try to compile the class "Common" it tells me that the class that I have extracted does not exist.
    The extracted class can not be compiled if I do not compile the "Common" class first. Solution?

    Cuestion 2.- In VS 2017 I have a project with different dlls. When compiling I want all the dlls to be included in the compiled as a single dll.
    Saturday, May 25, 2019 3:01 PM

All replies

  • Hi zequion1,

    Sorry for delay in reply.

    >>Cuestion 1.- In VS 2017 I have a class called "Common" that includes various useful functions to the rest of the classes.

    This question is related to compiler principles. Before compiling, compiler need to configure running environment, such as system environment, library location, reference relationship, precompiling, preprocessing and etc. Then compiler translates the source code for another program from a programing language into a sequence of machine instructions. And the reference means that A file is dependent on B file, then B file need to be compile first, to make the compiler know the the A file needs to use what. So the 'Common' class need to be compiled first.

    >>Cuestion 2.- In VS 2017 I have a project with different dlls. When compiling I want all the dlls to be included in the compiled as a single dll.

    From the above answer, there is no such appropriate method to merge the dlls into a single dll currently during compiling. May you could use ILMerge to merge the dlls as a single file per-build or post-build in visual studio.

    Any feedback will be expected.

    Best Regards,

    Dylan


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com


    Monday, May 27, 2019 9:19 AM
  • Cuestion 1.- If I extract the Function of A (Cls_Common), I can not compile A because it indicates that the function is missing.

    If I insert the function in B, I can not compile B because it indicates that there is a duplicate reference, since the function already exists in A.

    I have also seen that there is the possibility of indicating the solution explorer which Dll depends on another and you can also create a Fake dll but I do not know if you can use it for that matter.

    Cuestion 2.- I'm going to try IlMerge, but I think that function should exist in VS. Thank you

    Monday, May 27, 2019 10:56 AM
  • Hi zequion1,

    Thank you for reply.

    Cuestion 1. Did the function is independent in one class? If it is referred by function in one class, it will indicate this error.  Is the B class a sub class for A? If so, please delete the name function which is in A.

    If I misunderstand, could you share a sample using onedrive or github, then I will test it in my side.

    Cuestion 2. May you could follow the third suggestion from this answer to do in visual studio. 

    Best Regards,

    Dylan


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com


    Tuesday, May 28, 2019 8:57 AM
  • I have a Class called "Common" that contains general utilities. Inside it, there are .cs files each with their namespace and class. That is, instead of having everything inside "Common" I want to remove complete namespaces to its own dll. But then the problems start because of what I have indicated. It has a solution changing names provisionally, but it is a ridiculous situation.
    Tuesday, May 28, 2019 9:04 AM
  • Hi zequion,

    Thank you for details.

    >>instead of having everything inside "Common" I want to remove complete namespaces to its own dll. 

    Before a function is removed to other dll, you should confirm all reference relationship about it, to make sure it would be able to work. 

    And when the dll will be referred to other class file, you need to add it as reference for your project, then type the related code to call it. 

    And feedback will be expected.

    Best Regards,

    Dylan


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    Wednesday, May 29, 2019 2:48 AM
  • Thanks for your explanation.

    I have created two new classes. Without removing from the first class the NameSpace to extract after the second class:
    1.- I compiled the first class.
    2.- I have extracted the complete NameSpace from the first class and I have added it to the second class.
    3.- To the second class I have added the reference to the first class. 4.- I have compiled the second class.
    5.- To the first class I have eliminated the code that I have extracted to the second class.
    6.- To the first class I have added the reference to the second class.
    7.- I have compiled the second class.
    Everything went well.

    I have tried the same in my current project. In point 4, When trying to compile the second class, the error appears: "CS0246 C# The type or namespace name could not be found (are you using a directive or an assembly reference?)"

    The second class has the reference to the first, but although in the second I use the first one, it says that the NameSpace of the first class does not exist.

    I have checked everything several times and everything seems correct. And here I have stayed.
    Wednesday, May 29, 2019 6:28 AM
  • Hi zequion1,

    Thank you for reply.

    It seems that the namespace which is from "Common" is incompatibility with the library. Please make the framework of library same with the project.

    Note: right-click the project/ Application / Target Framework

    If the issue persists, please feel free to contact us.

    Best Regards,

    Dylan


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    Wednesday, May 29, 2019 1:20 PM
  • I can not find that option. Can you clarify it?
    Wednesday, May 29, 2019 2:33 PM
  • Hi zequion1,

    Please right-click Project >> click Properties >>select Appliaction >>choose target framework

    Best Regards,

    Dylan


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    Wednesday, May 29, 2019 2:52 PM
  • Thanks but i have the same framework 4.7.2 y the two classes. Another idea?

    How is it possible that in project A I add the reference to project B and I get the error that it does not find the namespace of project B, when I also have 3 more projects with the reference to project A and they work?

    Only classes fail me that I try to add new ones by extracting them from A
    .


    • Edited by zequion1 Wednesday, May 29, 2019 5:33 PM
    Wednesday, May 29, 2019 5:29 PM
  • Hi zequion1,

    Thank your for reply.

    According to your description, it seems that there is something wrong about extracting them from A.

    If possible, could you share code sample using one drive or screenshots about Class A? Then I would do extracting from A in my side, and it would help to explain what your issue is.

    Look forward to your reply.

    Best Regards,

    Dylan


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    Thursday, May 30, 2019 9:26 AM
  • I appreciate your response. At the moment I have rejected the idea of extracting classes from project A and I keep the classes that have reference to A. I can not pass code because it is very large. If I have time to try something else I will let you know.

    If you want to help and have time, you may be able to explain what the Fake Dll option is for and the options to indicate that one class depends on another at the time of compiling from the solution explorer. They are there, but I do not use it because I do not know what they are for.

    Thank you

    Thursday, May 30, 2019 9:53 AM
  • Hi zequion1,

    If there are other update information, please feel free to contact us.

    And about fake dll, I just use it in unit test project, you could learn more about from this MSDN DOC.

    Best Regards,

    Dylan


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    Wednesday, June 5, 2019 7:38 AM