By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,175 Members | 1,710 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,175 IT Pros & Developers. It's quick & easy.

csproj/vbproj definition available?

P: n/a
I'm developing an application that takes a csproj file as input (and
output).
I've searched for a definition or schema file for the csproj xml-file
to understand the possibilites and restrictions, but not found any...

Does anyone know if there is a "manual" for the csproj (and vbproj)
file?

Best regards
/Magnus

Mar 5 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Hello su*****@hotmail.com,

MSBuild has msbuild.xsd - it's schema for csproj files
I'm developing an application that takes a csproj file as input (and
output).
I've searched for a definition or schema file for the csproj xml-file
to understand the possibilites and restrictions, but not found any...
Does anyone know if there is a "manual" for the csproj (and vbproj)
file?

Best regards
/Magnus

---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
Mar 5 '06 #2

P: n/a
Hi,

Where can I find that msbuild.xsd file?

/Magnus

Mar 7 '06 #3

P: n/a
Hello SunYour,

Should be in c:\Program Files\Microsoft Visual Studio 8\Xml\Schemas\
I can't see it in my home pc (mb because Pro version of VS), but it was on
my work pc (teamsuite)

S> Hi,
S>
S> Where can I find that msbuild.xsd file?
S>
S> /Magnus
S>
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
Mar 7 '06 #4

P: n/a
Hello Michael,

Now i found it under C:\Program Files\Microsoft Visual Studio
8\Xml\Schemas\1033\MSBuild

Microsoft.Build.Core.xsd and
Microsoft.Build.Commontypes.xsd

The project files for 2003 and 2005 differs quite much.
The csproj for a 2003 project was easy to traverse with for example

//Fetch all resource (.resx) files in csproject file
XmlDocument xd = new XmlDocument();
xd.Load(projectFile);
XmlNodeList nlReferences =
xd.SelectNodes("VisualStudioProject/CSHARP/Files/Include/File[@DependentUpon
and @RelPath and contains(@RelPath,'.resx')]");

The same concept does not work with a .net 2005 csproj file.
It is not possible to load the csproj as an XmlDocument and use the
SelectNodes method.
I'm not sure it is because of the namespace attribute xmlns in the root
element:

<Project DefaultTargets="Build"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
...
</Project>

In the documentation, the SelectNodes method must have have no name
space definied in the xml document, or a prefix must be defined like:
xmlns:msb="http://schemas.microsoft.com/developer/msbuild/2003" (see
the extra :msb prefix)
In Microsoft.Build.Core.xsd, the prefix msb is defined, but not in the
project file... strange.

Is there another way to read and update the csproj file perhaps?
New instance of the Microsoft.Build.Core.xsd as a dataset and then load
the csproj file into it. After update, write it out as xml back
again... what do you think, any ideas? (i'll give it a try...)

Best regards
/Magnus

Mar 10 '06 #5

P: n/a
Hello again...

I found the

ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.NETDEVFX.v20.en/CPref0/html/T_Microsoft_Build_BuildEngine_Project.htm

document very useful :-)

a Microsoft.Build.BuildEngine.Project class that "Represents a project
that can be built using MSBuild." and A Project represents an MSBuild
project. It is a container for items, properties and targets. It can
load project content from in-memory XML or from an XML file, and can
save to an XML file, preserving most whitespace and all XML comments."

I think that is all I need...

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Build.BuildEngine;

namespace ListItemAndPropertiesCS
{
class Program
{
static void Main(string[] args)
{
// SET THIS TO POINT TO THE RIGHT LOCATION
Engine.GlobalEngine.BinPath =
@"C:\Windows\Microsoft.NET\Framework\v2.0.xxxxx ";

// Create a new empty project
Project project = new Project();

// Load a project
project.Load(@"c:\temp\validate.proj");

Console.WriteLine("Project Properties");
Console.WriteLine("----------------------------------");

// Iterate through the various property groups and
subsequently
// through teh various properties
foreach (BuildPropertyGroup propertyGroup in
project.PropertyGroups)
{
foreach (BuildProperty prop in propertyGroup)
{
Console.WriteLine("{0}:{1}", prop.Name,
prop.Value);
}
}

Console.WriteLine();
Console.WriteLine("Project Items");
Console.WriteLine("----------------------------------");

// Iterate through the various itemgroups
// and subsequently through the items
foreach (BuildItemGroup itemGroup in project.ItemGroups)
{
foreach (BuildItem item in itemGroup)
{
Console.WriteLine("{0}:{1}", item.Name,
item.Include);
}
}
}
}
}
/Magnus

Mar 10 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.