Before you can write and run queries to analyze a project, you need a snapshot of that project. Each snapshot contains a database for a single language and a copy of the code to show your query results on. If a project uses multiple languages, then you can have a snapshot for each language.
A snapshot is usually saved and used as a zip archive. However, to use the snapshot in CodeQL for Visual Studio you need to unzip it first. Once you've unzipped a snapshot, you can select it when running a query.
There are a few ways to obtain a snapshot to use in CodeQL for VS.
As of November 2019, "snapshots" have been renamed "CodeQL databases." The QL command-line tools (
odasa) that were previously used to create snapshots have been superseded by a more streamlined tool—the CodeQL CLI. CodeQL databases created with this new CLI are not directly compatible with CodeQL for VS, but you can run an additional command to convert them into the appropriate form. For more information, see the Database compatibility notes in the CodeQL help. You can still download and use CodeQL databases from LGTM as normal.
You can download CodeQL databases to analyze in CodeQL for Visual Studio from any project that is visible to you in LGTM Enterprise using the Integrations tab on the project page. The CodeQL databases for local analysis section contains the available databases for each language that has been detected. For more information, see Downloading CodeQL databases to run queries on in the help for LGTM Enterprise.
You may also analyze databases downloaded from LGTM.com, if they are compatible with your version of the
Creating a database using the CodeQL CLI
You can create and bundle a CodeQL database locally using the new CodeQL CLI. For more information, see Notes for legacy QL CLI users in the CodeQL help.
You can also create a snapshot locally using the QL command-line tools. You can convert this snapshot into the correct format for CodeQL for VS using the export command. For more information, see Exporting data for QL plugins and extensions and LGTM in the QL command-line tools help.
Once you have obtained a snapshot, you are ready to start running queries.
To find out more about snapshots, and how they are created, see What is a snapshot?