{"id":5303,"date":"2012-03-15T11:34:11","date_gmt":"2012-03-15T11:34:11","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/visualstudioalm\/2012\/03\/15\/the-code-index-sdk-part-2-bulk-indexing-assemblies-into-the-code-index\/"},"modified":"2019-02-14T17:59:34","modified_gmt":"2019-02-15T01:59:34","slug":"the-code-index-sdk-part-2-bulk-indexing-assemblies-into-the-code-index","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/devops\/the-code-index-sdk-part-2-bulk-indexing-assemblies-into-the-code-index\/","title":{"rendered":"The Code Index SDK \u2013 Part 2 \u2013 Bulk indexing assemblies into the code index"},"content":{"rendered":"<p><font color=\"#9b00d3\">Note that this post was updated on June 5th to provide updates concerning the Visual Studio 2012 RC. The changes are <font>highlighted<\/font>.<\/font><\/p>\n<p>In my <a href=\"http:\/\/blogs.msdn.com\/b\/visualstudioalm\/archive\/2012\/03\/13\/the-code-index-sdk.aspx\">last post<\/a>, I&rsquo;ve introduced the Code Index, explaining why use it, and how to get it. This post is about the first scenario that I mentioned: bulk indexing assemblies into the code Index. This topic requires that you have installed the VsVmSdk, as explained already.<\/p>\n<h3>3. How to bulk index assemblies in the Code Index ?<\/h3>\n<p>In&nbsp; Visual Studio 11 Beta, the only way to bulk-index assemblies is by using MsBuild. The supported scenarios are:<\/p>\n<p>&#8211; index assemblies as part of a build outside Visual Studio.<\/p>\n<p>&#8211; index an arbitrary set of assemblies from the command line<\/p>\n<h4>3.1 Bulk indexing of assemblies from the command line<\/h4>\n<h5>3.1.1 Presentation<\/h5>\n<p>You can use MSBuild directly from the command line to load artifacts into a specified code index. By default, the database will be created if it does not already exist.<\/p>\n<p>As a minimum, you will need to specify the artifacts to be loaded. Optionally, the following parameters can also be specified: database name, SQL server name, connection string, and whether the database should be created if it does not exist. If the connection string is specified then the database name and SQL Server name parameters will be ignored.<\/p>\n<h5>3.1.2 Examples<\/h5>\n<p>The following examples show how you can use MsBuild to index assemblies. For simplicity, here we suppose that we are running in a console window, and that the current path is the the folder where the MsBuild tasks are installed (See &sect; <a href=\"http:\/\/blogs.msdn.com\/b\/visualstudioalm\/archive\/2012\/03\/13\/the-code-index-sdk.aspx\">2.3<\/a>). If this is not the case, of course, you need to provide the full path for <strong>Microsoft.Repository.targets<\/strong>. Also note that the commands should really be on one line (but the blog page is too narrow for me to write everything on line, so I cut the command into 2 lines)<\/p>\n<table border=\"1\" cellspacing=\"0\" cellpadding=\"4\" width=\"500\">\n<tbody>\n<tr>\n<td valign=\"top\" width=\"521\">\n<p><font face=\"Consolas\">msbuild Microsoft.Repository.targets \/t:LoadFiles             <br>\/p:LoadFileSpec=*.dll<\/font><\/p>\n<p>Effect: loads all matching files from the current directory into the default code index. A new database will be created if necessary<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"521\">\n<p><font face=\"Consolas\">msbuild Microsoft.Repository.targets \/t:LoadFiles&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>\/p:LoadFileSpec=*.dll \/p:CreateRepository=false<\/font><\/p>\n<p>Effect: loads all matching files from the current directory into the default code index. The <b>database<\/b> will <b>not be created<\/b> if it does not already exist<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"521\">\n<p><font face=\"Consolas\">msbuild Microsoft.Repository.targets \/t:LoadFiles&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>\/p:LoadFileSpec=<font>&#8220;<\/font>***.dll;***.exe<font>&#8220;<\/font><\/font><\/p>\n<p>Effect: loads all matching files from the current directory <b>and sub-directories<\/b> into the default Repository (note the MsBuild syntax <font face=\"Consolas\">**<\/font> means &ldquo;recursively&rdquo;)<i><\/i><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"521\">\n<p><font face=\"Consolas\">msbuild Microsoft.Repository.targets \/t:LoadAFiles&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>\/p:LoadFileSpec=*.dll \/p:RepositoryDb=MyCodeIndex<\/font><\/p>\n<p>Effect: loads all matching files from the current directory into the <b>specified database<\/b> using the default SQL server<i><\/i><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"521\">\n<p><font face=\"Consolas\">msbuild Microsoft.Repository.targets \/t:LoadFiles&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>\/p:LoadFileSpec=*.dll \/p:RepositoryServer=MyDivisionSqlServer<\/font><\/p>\n<p>Effect: loads all matching files from the current directory into the default database on the <b>specified SQL server<\/b><i><\/i><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"521\">\n<p><font face=\"Consolas\">msbuild Microsoft.Repository.targets \/t:LoadFiles \/p:LoadFileSpec=*.dll             <br> \/p:RepositoryServer=MyDivisionSqlServer \/p:RepositoryDb=MyCodeIndex<\/font><\/p>\n<p>Effect: loads all matching files from the current directory into the specified database on the specified SQL server<i><\/i><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><font face=\"Segoe UI\"><\/font><\/p>\n<p>The command can be summarized as the following (between squared brackets I&rsquo;ve represented optional commands)<\/p>\n<p><font face=\"Consolas\">Msbuild     <br>%ProgramFiles(x86)%MSBuildMicrosoftVisualStudiov11.0RepositoryMicrosoft.Repository.targets       <br>[ \/t:LoadFiles ]       <br>\/p:LoadFileSpec=<i>Folder<\/i>*.dll | <i>Folder<\/i>***.dll      <br>[ \/p:CreateRepository=false ]       <br>[ \/p:RepositoryServer=<i>SqlServerInstanceName<\/i> ]       <br>[ \/p:RepositoryDb=<i>DatabaseName<\/i> ]<\/font><\/p>\n<h4>3.2 Creating a standalone MsBuild project to index specific assemblies<\/h4>\n<p>Another way of indexing assemblies is by creating an MSBuild project that sets the configuration properties (e.g. files to index, connection string etc &hellip;) then invokes the new Repository tasks and targets directly. You will then be able to index the assemblies simply by building the project from the command line e.g.    <\/p>\n<p><font face=\"Consolas\">msbuild SampleProject.proj<\/font><\/p>\n<p>The following example (<font face=\"Consolas\">SampleProject.proj<\/font>) shows a custom project that will load all of the .exe and the .dll files which name starts with &ldquo;Build&rdquo; located in the same directory as the target file into a database folder named &ldquo;TargetFolder&rdquo; of a database called &ldquo;MyTestDb&rdquo;. This database will be created under <font face=\"Consolas\">S:SqlData<\/font>.<\/p>\n<table border=\"1\" cellspacing=\"0\" cellpadding=\"5\" width=\"550\">\n<tbody>\n<tr>\n<td valign=\"top\" width=\"500\">\n<p><font face=\"Consolas\">&lt;?xml version=&#8221;1.0&#8243; encoding=&#8221;utf-8&#8243; ?&gt;              <br> &lt;Project <strong>DefaultTargets=&#8221;LoadArtifacts&#8221;<\/strong> ToolsVersion=&#8221;4.0&#8243;               <br>&nbsp;&nbsp; xmlns=&#8221;http:\/\/schemas.microsoft.com\/developer\/msbuild\/2003&#8243;&gt;<\/font><\/p>\n<p>         <font face=\"Consolas\"><\/font>          <\/p>\n<p><font face=\"Consolas\"> &lt;!&#8211; Custom project file to load all of the assemblies and executables in the same folder as the project file. Note that the &#8220;DefaultTargets&#8221; property has been set above to &#8220;LoadArtifacts&#8221;. &#8211;&gt;<\/font><\/p>\n<p>         <font face=\"Consolas\"><\/font>          <\/p>\n<p><font face=\"Consolas\">&lt;PropertyGroup&gt;<\/font><\/p>\n<p>         <font face=\"Consolas\"><\/font>          <\/p>\n<p><font face=\"Consolas\">&lt;!&#8211; Change the directory in which the database will be created. &ndash;&gt;              <br>&lt;<strong>RepositoryDirectory<\/strong>&gt;S:SqlData&lt;\/<strong>RepositoryDirectory<\/strong>&gt;<\/font><\/p>\n<p>         <font face=\"Consolas\"><\/font>          <\/p>\n<p><font face=\"Consolas\">&lt;!&#8211; Change the database into which the data will be loaded. &ndash;&gt;              <br><font>&lt;<strong>Repository<\/strong>&gt;MyTestDb&lt;\/<strong>Repository<\/strong>&gt;<\/font><\/font><\/p>\n<p>         <font face=\"Consolas\"><\/font>          <\/p>\n<p><font face=\"Consolas\">&lt;!&mdash;- Repository Folder into which the data will be loaded&mdash;&gt;              <br>&lt;<strong>TargetFolder<\/strong>&gt;LastVersion&lt;\/<strong>TargetFolder<\/strong>&gt;<\/font><\/p>\n<p>         <font face=\"Consolas\"><\/font>          <\/p>\n<p><font face=\"Consolas\">&lt;\/PropertyGroup&gt;<\/font><\/p>\n<p>         <font face=\"Consolas\"><\/font>          <\/p>\n<p><font face=\"Consolas\">&lt;ItemGroup&gt;<\/font><\/p>\n<p>         <font face=\"Consolas\"><\/font>          <\/p>\n<p><font face=\"Consolas\">&lt;!&#8211; Specify the artifacts to load &ndash;&gt;              <br>&lt;<strong>ArtifactsToLoad<\/strong> Include=&#8221;Build*.dll&#8221; \/&gt;               <br>&lt;<strong>ArtifactsToLoad<\/strong> Include=&#8221;*.exe&#8221; \/&gt;<\/font><\/p>\n<p>         <font face=\"Consolas\"><\/font>          <\/p>\n<p><font face=\"Consolas\">&lt;\/ItemGroup&gt;<\/font><\/p>\n<p>         <font face=\"Consolas\"><\/font>          <\/p>\n<p><font face=\"Consolas\">&lt;!&#8211; Import the core Repository tasks and targets&#8211;&gt;<\/font><\/p>\n<p>         <font face=\"Consolas\"><\/font>          <\/p>\n<p><strong><font face=\"Consolas\">&lt;Import Project=&#8221;$(MSBuildExtensionsPath)MicrosoftVisualStudiov11.0RepositoryMicrosoft.Repository.targets&#8221;\/&gt;<\/font><\/strong><\/p>\n<p>         <font face=\"Consolas\"><\/font>          <\/p>\n<p><font face=\"Consolas\">&lt;\/Project&gt;<\/font><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><font color=\"#9b00d3\">Note that, in the code index SDK Beta, the element describing the database used to be <font face=\"Consolas\">&lt;<strong>RepositoryDb<\/strong>&gt;MyTestDb&lt;\/<strong>RepositoryDb<\/strong>&gt;. <\/font>From Visual Studio 2012 RC, it is now <font face=\"Consolas\">&lt;<strong>Repository<\/strong>&gt;MyTestDb&lt;\/<strong>Repository<\/strong>&gt;<\/font><\/font><\/p>\n<p>&nbsp;<\/p>\n<h4>3.3 Reference for the MsBuild tasks<\/h4>\n<p>I&rsquo;ll recap here what you can use in your msbuild projects:<\/p>\n<h5>3.3.1 MSBuild properties and item groups<\/h5>\n<p>The following properties and item groups can be used to configure the loading process.<\/p>\n<table border=\"1\" cellspacing=\"0\" cellpadding=\"4\">\n<tbody>\n<tr>\n<td valign=\"top\" width=\"212\">\n<p><b>Item<\/b><\/p>\n<\/td>\n<td valign=\"top\" width=\"409\">\n<p><b>Description<\/b><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"212\">\n<p><font face=\"Consolas\">$(Repository)<\/font><\/p>\n<p><font color=\"#9b00d3\">Used to be <font face=\"Consolas\">$(RepositoryDb) <\/font>in Beta<\/font><\/p>\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/td>\n<td valign=\"top\" width=\"409\">\n<p>Name of the database into which data should be loaded.<\/p>\n<p>Ignored if <font face=\"Consolas\">$(RepositoryConnectionString)<\/font> is specified.<\/p>\n<p><b>Default value:<\/b> <em><font>Microsoft.VsCodeIndex<\/font><\/em><\/p>\n<p><font color=\"#9b00d3\">Default value used to be <i>Repository <\/i>in Beta<\/font><\/p>\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"212\">\n<p><font face=\"Consolas\">$(RepositoryServer)<\/font><\/p>\n<\/td>\n<td valign=\"top\" width=\"409\">\n<p>Name of the SQL Server.<\/p>\n<p>Ignored if <font face=\"Consolas\">$(RepositoryConnectionString)<\/font> is specified.<\/p>\n<p><b>Default value:<\/b> <i>(localdb)v11.0<\/i><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"212\">\n<p><font face=\"Consolas\">$(RepositoryConnectionString)<\/font><\/p>\n<\/td>\n<td valign=\"top\" width=\"409\">\n<p>Full connection string to database to use.<\/p>\n<p><b>Default value:<\/b> calculated using <font face=\"Consolas\">$(RepositoryDb)<\/font> and <font face=\"Consolas\">$(RepositoryServer)<\/font>.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"212\">\n<p><font face=\"Consolas\">$(CreateRepository)<\/font><\/p>\n<\/td>\n<td valign=\"top\" width=\"409\">\n<p>Flag that indicates whether the specified Repository database will be created if it does not already exist.<\/p>\n<p><b>Default value:<\/b> <i>True<\/i><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"212\">\n<p><font face=\"Consolas\">$(RepositoryDirectory)<\/font><\/p>\n<\/td>\n<td valign=\"top\" width=\"409\">\n<p>Operating system directory in which the new database will be created (in order to control where to locate the database files)<\/p>\n<p>Ignored if a new database is not created.<\/p>\n<p><b>Default value:<\/b> <i>null<\/i><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"212\">\n<p><font face=\"Consolas\">@(ArtifactUris)<\/font><\/p>\n<\/td>\n<td valign=\"top\" width=\"409\">\n<p>The list of artifacts to load (See the MsBuild targets below)<\/p>\n<p><b>Default value:<\/b> <i>null<\/i><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"212\">\n<p><font face=\"Consolas\">$(TargetFolder)<\/font><\/p>\n<\/td>\n<td valign=\"top\" width=\"409\">\n<p>The target code index folder into which the artifacts should be loaded. In the code index, the information about indexed assemblies is stored in folders, which are the unit of deletion. Several assemblies can be stored in the same folder. If this parameter is not provided, then the name of the folder is computed (from the assembly name and a GUID)<\/p>\n<p><b>Default value:<\/b> <i>null<\/i><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"212\">\n<p><font face=\"Consolas\">$(LoadFileSpec)<\/font><\/p>\n<\/td>\n<td valign=\"top\" width=\"409\">\n<p>File specification of files to load. <\/p>\n<p>Examples of usage from the command line:<\/p>\n<p><font face=\"Consolas\">\/p:LoadFileSpec=*.dll <\/font><\/p>\n<p>         <font face=\"Consolas\"><\/font>          <\/p>\n<p><font face=\"Consolas\">\/p:LoadFileSpec=***.dll<\/font><\/p>\n<p>         <font face=\"Consolas\"><\/font>          <\/p>\n<p><font face=\"Consolas\">\/p:LoadFileSpec=*.dll;*.exe<\/font><\/p>\n<p><b>Default value:<\/b> <i>null<\/i><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h5>3.3.2 User-callable MSBuild targets<\/h5>\n<p>The following targets can be called<\/p>\n<table border=\"1\" cellspacing=\"0\" cellpadding=\"4\">\n<tbody>\n<tr>\n<td valign=\"top\" width=\"101\">\n<p><b>Target<\/b><\/p>\n<\/td>\n<td valign=\"top\" width=\"522\">\n<p><b>Description<\/b><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"101\">\n<p><font face=\"Consolas\">LoadArtifacts<\/font><\/p>\n<\/td>\n<td valign=\"top\" width=\"522\">\n<p>Low level task that provides maximum control of the execution of the loading process i.e. the user can specify all of the available configuration options. <\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"101\">\n<p><font face=\"Consolas\">LoadFiles<\/font><\/p>\n<\/td>\n<td valign=\"top\" width=\"522\">\n<p>Wrapper around <font face=\"Consolas\">LoadArtifacts<\/font> to simplifying loading files from the command line. The user specifies the files to load using the <font face=\"Consolas\">$(LoadFileSpec<i>)<\/i><\/font> property.<\/p>\n<p>The target uses this property to set <font face=\"Consolas\">@(ArtifactsToLoad)<\/font> and then calls the <font face=\"Consolas\">LoadArtifacts<\/font> target.<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n","protected":false},"excerpt":{"rendered":"<p>Note that this post was updated on June 5th to provide updates concerning the Visual Studio 2012 RC. The changes are highlighted. In my last post, I&rsquo;ve introduced the Code Index, explaining why use it, and how to get it. This post is about the first scenario that I mentioned: bulk indexing assemblies into the [&hellip;]<\/p>\n","protected":false},"author":77,"featured_media":45953,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[226,1],"tags":[],"class_list":["post-5303","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ci","category-devops"],"acf":[],"blog_post_summary":"<p>Note that this post was updated on June 5th to provide updates concerning the Visual Studio 2012 RC. The changes are highlighted. In my last post, I&rsquo;ve introduced the Code Index, explaining why use it, and how to get it. This post is about the first scenario that I mentioned: bulk indexing assemblies into the [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/posts\/5303","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/users\/77"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/comments?post=5303"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/posts\/5303\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/media\/45953"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/media?parent=5303"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/categories?post=5303"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/tags?post=5303"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}