This tip addresses two issues when using Visual Studio to edit your NT code
- The annoying message "The project has been changed outside the editor, do you want to reload?" (or something like that)
- The crazy amount of warnings (588 of 'em IIRC)
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!
- Create a new Solution in the "bin" folder (That's the parent directory of the "Custom" folder)
- Right click the Project that was created with the solution and select remove
- Delete the Project folder that was created for the solution
- 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)
- Add the Project file to the solution
The Project (.csproj) in Detail
<Project Sdk="Microsoft.NET.Sdk">
<TargetFramework>net472</TargetFramework>
<NoWarn>1701;1702;0618</NoWarn>
<ItemGroup> <Compile Remove="NinjaTrader.Vendor.cs" /> </ItemGroup>
<Reference Include="InfragisticsWPF4.DataPresenter.v15.1"> <HintPath>..\..\..\..\..\..\Program Files (x86)\NinjaTrader 8\bin64\InfragisticsWPF4.DataPresenter.v15.1.dll</HintPath> </Reference> ...
<Reference Include="System.ComponentModel.DataAnnotations" /> ...
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
Comment