Microsoft Visual Studio: Difference between revisions

From Wildsong
Jump to navigationJump to search
Brian Wilson (talk | contribs)
Brian Wilson (talk | contribs)
mNo edit summary
Line 3: Line 3:
2018-04-15 Updated to 15.6.4 (on [[Murre]]) and .Net Framework 4.7.1
2018-04-15 Updated to 15.6.4 (on [[Murre]]) and .Net Framework 4.7.1


I want to try to develop some ArcObjects tools  
== Overview ==
 
Originally I wanted to try to develop some ArcObjects tools  
and I want to access those tools from Python.
and I want to access those tools from Python.
So, that gives me two tasks: set up C# and the ESRI SDKs and set up Python.


I have ESRI and Anaconda versions of Python. I originally installed the Anaconda versions
I have ESRI and Anaconda versions of Python. I originally installed the Anaconda versions
to use Spyder. I like the conda package and environment management so I want (at least for now)
to use Spyder. I like the conda package and environment management so I want (at least for now)
to continue using them.
to continue using them.
Going forward ESRI blessed Anaconda by including it in ArcGIS Pro.


I used to be a Windows developer so I was in Visual Studio sessions all day, every day.
I used to be a Windows developer so I was in Visual Studio sessions all day, every day.
So far it's working nearly as well with Python as it did with C#. Integration with ESRI/ArcPy has been seamless.
So far it's working nearly as well with Python as it did with C#. Integration with ESRI/ArcPy has been seamless.


== Installation ==
== Installation notes ==


Go to https://www.visualstudio.com/
For downloads and official help
go to https://www.visualstudio.com/


=== Workloads ===
=== Workloads ===
Line 33: Line 36:
run to your administrator every time you need a new Python package.'''
run to your administrator every time you need a new Python package.'''


== Set up ==
=== Set up ===


=== Select the Python you want ===
==== Select the Python you want ====


# Tools->Python->Python Environment
# Tools->Python->Python Environment
# Select the one for ESRI Python 2.7.14 64-bit for modern ArcMap work or 32-bit if you need Personal Geodatabases
# Select the one for ESRI Python 2.7.14 64-bit for modern ArcMap work or 32-bit if you need to use old Personal Geodatabases.
# Choose "Make this the default for new projects"
# Choose "Make this the default for new projects"


=== Tabs at 4, really? ===
You can change the python that a project uses anytime later.
 
==== Tabs at 4, really? ====


Microsoft is still clinging to settings tabs in the text editor at 4.
Microsoft is still clinging to settings tabs in the text editor at 4.
Line 61: Line 66:
So the answer is to set it to "insert spaces", never put tabs anywhere, it's 2018 and saving a few hundred bytes by substituting tabs for spaces is no longer important.
So the answer is to set it to "insert spaces", never put tabs anywhere, it's 2018 and saving a few hundred bytes by substituting tabs for spaces is no longer important.


=== Use Git for version control ===
==== Use Git for version control ====


Go to "Tools -> Options -> Source Control" and under "Plug-in Selection", switch to Git.
Go to "Tools -> Options -> Source Control" and under "Plug-in Selection", switch to Git.
Line 73: Line 78:
the same things: a bash command shell and git commands.
the same things: a bash command shell and git commands.


=== Use the experimental support for Intellisense ===
==== Enable the experimental support for Intellisense ====


This is a checkbox under Tools->Options->Python->Experimental
This is a checkbox under Tools->Options->Python->Experimental


=== ArcObjects 10.6 SDK ===
Intellisense is one of the main reasons to use Visual Studio. That's the code completion feature,
where for example you type "arcpy.ListDataSets(" and VS pops up what arguments ListDatasets needs.
 
== Developing extensions ==
 
I built some ESRI code samples to prove to myself it works but have not really gone further yet.


If you want to try to compile C# ArcObjects code, you need the SDK from ESRI
If you want to try to compile C# ArcObjects code, you will need the "workload" for C# and .Net.
and you will need the "workload" for C# and .Net.
You will need to install the ArcObjects SDK from ESRI.


https://desktop.arcgis.com/en/system-requirements/latest/arcobjects-sdk-system-requirements.htm
https://desktop.arcgis.com/en/system-requirements/latest/arcobjects-sdk-system-requirements.htm
Line 87: Line 97:


Microsoft .NET Framework 4.5 or higher; I am using 4.7.1  
Microsoft .NET Framework 4.5 or higher; I am using 4.7.1  
Note you can download .Net Frameworks from inside Visual Studio.
Note you can download additional .Net Frameworks from inside Visual Studio.


Samples will be found in C:\Program Files (x86)\ArcGIS\DeveloperKit10.6
Code samples will be found in C:\Program Files (x86)\ArcGIS\DeveloperKit10.6


=== ArcGIS Add-ins ===
=== ArcGIS Add-ins ===

Revision as of 18:52, 25 June 2018

I am using the 2017 Community edition.

2018-04-15 Updated to 15.6.4 (on Murre) and .Net Framework 4.7.1

Overview

Originally I wanted to try to develop some ArcObjects tools and I want to access those tools from Python.

I have ESRI and Anaconda versions of Python. I originally installed the Anaconda versions to use Spyder. I like the conda package and environment management so I want (at least for now) to continue using them.

Going forward ESRI blessed Anaconda by including it in ArcGIS Pro.

I used to be a Windows developer so I was in Visual Studio sessions all day, every day. So far it's working nearly as well with Python as it did with C#. Integration with ESRI/ArcPy has been seamless.

Installation notes

For downloads and official help go to https://www.visualstudio.com/

Workloads

When you install VS, you don't get tons of different languages installed, you have to pick what you want. The packages are called "workloads", see https://visualstudio.microsoft.com/vs/visual-studio-workloads/.

For reasons I mention on the Anaconda page, do NOT install the versions of Python and Anaconda that are available in the Visual Studio installer. Install them separately. Install only the "Python development" workload and turn off Python 3x64; Visual Studio won't have any problem finding and using external ESRI and Anaconda packages that you install separately.

The reason (as mentioned in my Anaconda page) is you won't need administrative permission to install or update Anaconda packages.

If you install the Microsoft Anaconda workload, you will have to run to your administrator every time you need a new Python package.

Set up

Select the Python you want

  1. Tools->Python->Python Environment
  2. Select the one for ESRI Python 2.7.14 64-bit for modern ArcMap work or 32-bit if you need to use old Personal Geodatabases.
  3. Choose "Make this the default for new projects"

You can change the python that a project uses anytime later.

Tabs at 4, really?

Microsoft is still clinging to settings tabs in the text editor at 4. It should be tabs at 8 and insert spaces not "Keep tabs". Set it thus and avoid a world of pain*. "Insert spaces" means it will use spaces instead of mixing tabs and spaces.

Tools -> Options -> Python -> Tabs

SET TABS AT 8!!
SET TABS AT 8!!


  • world of pain - you really are curious about this?

Since Python cares (a lot) about indentation, having the indents look consistent is not enough, eventually you will end up with a mixture of spaces and tabs in your .py file, and one line will have for example two tabs (2 X "tabs at 4" = 8) and it lines up with all the others which have 8 spaces. Then it will no longer compile, giving you the error about indentation being wrong even though everything looks just fine. (There will be a yellow line in the editor that you will ignore because everything looks okay.)

So the answer is to set it to "insert spaces", never put tabs anywhere, it's 2018 and saving a few hundred bytes by substituting tabs for spaces is no longer important.

Use Git for version control

Go to "Tools -> Options -> Source Control" and under "Plug-in Selection", switch to Git.

I set it this way, but so far I still use git from the command line.

I tried out the Github extension for VS and it works but I don't really see it as an advantage over using the commands. I use the git bash shell all day on Windows 7. I suppose if you never use bash it might be more difficult.

In Windows 10 there is the WSL "Windows Subsystem for Linux", comes from Microsoft, and gets you a variation on the same things: a bash command shell and git commands.

Enable the experimental support for Intellisense

This is a checkbox under Tools->Options->Python->Experimental

Intellisense is one of the main reasons to use Visual Studio. That's the code completion feature, where for example you type "arcpy.ListDataSets(" and VS pops up what arguments ListDatasets needs.

Developing extensions

I built some ESRI code samples to prove to myself it works but have not really gone further yet.

If you want to try to compile C# ArcObjects code, you will need the "workload" for C# and .Net. You will need to install the ArcObjects SDK from ESRI.

https://desktop.arcgis.com/en/system-requirements/latest/arcobjects-sdk-system-requirements.htm

ArcGIS Desktop, ArcGIS Engine, or ArcGIS Server is required to develop with ArcObjects SDK.

Microsoft .NET Framework 4.5 or higher; I am using 4.7.1 Note you can download additional .Net Frameworks from inside Visual Studio.

Code samples will be found in C:\Program Files (x86)\ArcGIS\DeveloperKit10.6

ArcGIS Add-ins

I am starting a separate page: ArcGIS Add-ins