Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Pro Tip: Get rid of VS Warnings!

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Pro Tip: Get rid of VS Warnings!


    This tip addresses two issues when using Visual Studio to edit your NT code
    1. The annoying message "The project has been changed outside the editor, do you want to reload?" (or something like that)
    2. The crazy amount of warnings (588 of 'em IIRC)
    Context/Background

    Visual Studio/Visual Studio Code only serves as a glorified editor when used in conjunction with NinjaTrader. In fact, you can use any old editor you want. NinjaTrader monitors the files under the "Custom" folder and calls the C# compiler (csc.exe) to compile the custom DLL whenever any file changes. The ninjas have graciously provided a Solution file that includes a Project that we can open in VS/VS Code in order to make our changes (Thank you ninjas).

    NinjaTrader modifies the custom project every time it recompiles, hence the first issue. If you think about that for a second or two, the solution to this problem will probably come to you (Was there a pun intended there? "H" "E" double hockey sticks yeah ).

    The second problem has two causes. First, there is an obsolete class being used so there are warnings for that. Second, there is a redefinition of the Indicator class in the NinjaTrader.Vendor.dll that is being referenced so there are warnings for that. The solution (Oops! I did it again - hope you don't have that trade_marked Britney) to the second problem is just an extension of the thought process of solving the first.

    The Solution (I can't help myself - somebody stop me please)
    • Problem 1 - The annoying project changed message
      • Fact 1: VS is only used for editing
      • Fact 2: NT invokes the compiler itself and uses the resulting compiled assembly
      • Fact 3: Considering Fact 2, whatever assembly you generate from VS is irrelevant and not used
      • Answer: Create your own Solution and Project! NT won't know about that and so it can't modify what it doesn't know, right?
    • Problem 2 - The warnings
      • Fact 1: Consider all the facts from the previous solution
      • Fact 2: Indicator class is redefined in NinjaTrader.Vendor.dll
      • Fact 3: You now have your own Solution and Project that NT doesn't know about
      • Answer: Don't include a reference to NinjaTrader.Vendor.dll in your Project!
    Steps
    1. Create a new Solution in the "bin" folder (That's the parent directory of the "Custom" folder)
    2. Right click the Project that was created with the solution and select remove
    3. Delete the Project folder that was created for the solution
    4. Place the attached Project file (Change the extension to .csproj - the forum doesn't allow attaching files with .csproj extension) in the "Custom" folder (Rename it to whatever you called the Project used to create the solution)
    5. Add the Project file to the solution
    That's it! Now just open this solution when you need to edit and you won't have the deluge of NT warnings!

    The Project (.csproj) in Detail

    Code:
    <Project Sdk="Microsoft.NET.Sdk">
    Use the new csproj file format (as of 2017). This is simpler because you don't have to include all the files that are part of the project. It automatically picks up all files in the project folder and subfolders. This means if there are files you want excluded from compilation, you'll need to right-click each (or multi-select) and select "Exclude from project". If you are not using at least VS 2017, you'll need to use the old project format

    Code:
    <TargetFramework>net472</TargetFramework>
    I use .NET 4.7.2 to compile my code so this specifies that version. If you want to know how to do that, check out my post Hack Alert: Compile with .net 4.6!. Otherwise, change it to net45, net451 or net452 (I don't remember which NT uses off the top of my head - it might be the same csc.exe for all three so it might not matter).

    Code:
    <NoWarn>1701;1702;0618</NoWarn>
    Added the "0618". This is the code for "Obsolete". You can remove this if you want to address this differently.

    Code:
      <ItemGroup>
        <Compile Remove="NinjaTrader.Vendor.cs" />
      </ItemGroup>
    Since we are not including NinjaTrader.Vendor.dll in the references, we need to exclude this file from compilation since it references that DLL.

    Code:
    <Reference Include="InfragisticsWPF4.DataPresenter.v15.1">
        <HintPath>..\..\..\..\..\..\Program Files (x86)\NinjaTrader 8\bin64\InfragisticsWPF4.DataPresenter.v15.1.dll</HintPath>
    </Reference>
    ...
    These are assembly references to DLLs in the NinjaTrader program files folder. If you are using the 32 bit NT executable then change "\bin64" to "\bin" in the HintPath. If your installation is not default and these files are located elsewhere, you will need to update the path. If you are reading this way in the future and there are additional references added to the Custom project by the ninjas then first - call me and give me tomorrow's lottery numbers (today is Feb 10, 2020) - second, add the additional references.

    Code:
    <Reference Include="System.ComponentModel.DataAnnotations" />
    ...
    These are framework references. Same as above, add whatever new references that were added to the Custom project after the date of this post.

    NOTES:
    • There will be compilation errors in about duplicate attributes. The simplest fix is to comment out the appropriate lines in assembly.cs
    • You don't have to edit the csproj directly, you can use the VS Solution Explorer to add/remove references as needed
    • If you are not creating additional assemblies to be referenced by NT, you might not need to create a Solution, just use the new Project
    • If you are using NinjaTrader.Vendor.dll then consider
      • Exclude the files that reference it from this project and use the provided Custom project when changes are needed
      • Exclude the files that reference it from this project and open them individually when changes are needed
      • Create another Solution/Project specifically for editing those
    • If you use Hack Alert: Compile with .net 4.6!, be aware of the following:
      • After new Windows updates are installed, you may need to do the renames again if the framework was updated

    Hope this works for you and you weren't intimidated by the length of the post. It's overall very simple, I just wanted to fully explain the details

    Wil
    Attached Files
    Last edited by wbennettjr; 02-10-2020, 10:29 AM. Reason: Added note about duplicate attributes.

    #2
    In the post Troubles with Custom Project Environment, ChazJ asked about files that are excluded from compilation using the NT Script Editor. Apparently, NT prefixes such files with "@@". Since Visual Studio doesn't know about this convention, it will produce build errors if there are errors in these files. To have visual studio ignore these files, add the following to the csproj:

    Code:
    <ItemGroup>
        <Compile Remove="**\@@*.*" />
    </ItemGroup>

    Comment


      #3
      Originally posted by wbennettjr View Post
      In the post Troubles with Custom Project Environment, ChazJ asked about files that are excluded from compilation using the NT Script Editor. Apparently, NT prefixes such files with "@@". Since Visual Studio doesn't know about this convention, it will produce build errors if there are errors in these files. To have visual studio ignore these files, add the following to the csproj:

      Code:
      <ItemGroup>
      <Compile Remove="**\@@*.*" />
      </ItemGroup>
      thanks! useful.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by samish18, Today, 08:31 AM
      1 response
      1 view
      0 likes
      Last Post NinjaTrader_Clayton  
      Started by Creamers, 09-08-2023, 10:26 AM
      6 responses
      157 views
      0 likes
      Last Post JonyGurt  
      Started by funk10101, Today, 08:14 AM
      1 response
      2 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Started by trilliantrader, Today, 08:16 AM
      2 responses
      6 views
      0 likes
      Last Post trilliantrader  
      Started by bill2023, Yesterday, 08:51 AM
      3 responses
      22 views
      0 likes
      Last Post bltdavid  
      Working...
      X