开发者

How to make intellisense work with NANT Files in Visual Studio 2008?

开发者 https://www.devze.com 2023-02-13 23:44 出处:网络
I started with an Empty Project, and tried to get my build file setup with Here\'s what I have tried so far:

I started with an Empty Project, and tried to get my build file setup with

Here's what I have tried so far:

  1. Found out what version of NAnt I'm using by running NAnt with the -help option.
  2. In the following string replaced the version of NAnt I'm using in the following URL:
    • http://nant.sourceforge.net/release/<my NAnt version>/nant.xsd
    • In this example, lets say it's 0.90.
  3. Downloaded the file: from the above URL to %VS_HOME%\Common7\Packages\schemas\xml
    • http://nant.sourceforge.net/release/0.90/nant.xsd
  4. Opened my buildfile in VS (from instide my solution and project)
  5. From the menu clicked XML->Schemas... to add add the nant.xsd I 开发者_StackOverflow中文版downloaded earlier to the IDE.
  6. After adding the schema made sure that it had a green checkmark next to it in the Use column of the XML Schemas window.
  7. Added the following attribute in the <project> element of my build file:
    • <project ... xmlns="http://nant.sourceforge.net/release/0.90/nant.xsd" >
  8. Clicked OK on XML Schemas window.
  9. Lastly, I reopened my buildfile with the open with... the XML Editor.

After performing the above procedure in the Error List I get a list in the messages section but I don't get any intellisense suggestions when typing (other than the defaults for XML, like !--, ![CDATA[, and ?)

Is there something else I need to change to make this work in VS2008?


I added the nant.xsd file that ships with the version I have (0.85) to the schemas set in VS and then added this to my build file:

<project xmlns="http://nant.sf.net/release/0.85/nant.xsd" name="foo">

And it worked fine. Are you sure the XML namespace you're declaring for the 0.90 release is correct? Maybe it's sf.net rather than sourceforge.net.


Take a look at the nantschema task. You can get nant to puke out its own XML schema which will include any third-party extensions (nantcontrib, custom tasks, etc).

I have setup a website on my dev machine called nant.myprojectname.com (where myprojectname is replaced by whatever I want to call my project) and I get nant to copy the schema xsd file there as part of the build process. I just put nant.myproject.com into the local hosts file to get it to resolve on the local dev machine - I don't really need the schema available elsewhere.

I then put the following into the nant project element :

<project
    xmlns="http://www.myprojectname.com/myprojectnamenant"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="www.myprojectname.com/myprojectnamenant http://nant.myprojectname.com/myprojectnamenant.xsd"
    default="go"
    name="myprojectname">

The schemaLocation attribute tells Visual Studio (or whatever) to look at http://nant.myprojectname.com/myprojectnamenant.xsd for the schema. May need to reload VS before Intellisense kicks in.


I'm a bit late to this question, but I was searching for the solution to this problem with the twist of wanting intellisense for NAntContrib as well. To do this follow these steps:

Step 1: You need to create a build script for the new nant.sxd, let's call this file nantxsd.build that includes the NAntContrib tasks:

<project name="nant" default="go">
    <property name="NAntContrib" value="E:\NAnt\nantcontrib-0.91-bin\nantcontrib-0.91\bin" />
    <target name="go">
        <loadtasks assembly="${NAntContrib}\NAnt.Contrib.Tasks.dll" />
        <nantschema output="nant.xsd" target-ns="http://nant.sf.net/release/0.91/nant.xsd"/>
    </target>
</project>

Step 2: Then build the new nant.xsd file from the command line. If you have installed NAnt you should be able to open the command line window in the same directory as the nanntxsd.build script and run:

nant /f:nantxsd.build

Step 3: Copy the new nant.xsd to the Visual Studio XML\Schemas folder. For example:

"C:\Program Files (x86)\Microsoft Visual Studio 10.0\Xml\Schemas\nant.xsd"

0

精彩评论

暂无评论...
验证码 换一张
取 消