473,382 Members | 1,717 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

How to generate the .Net project file ".*proj" dynamically in .Net 2.0 ???

Hi,

I am having few .net source files(.cs or .vb) and I want to dynamically generate the corresponding .net project file(.csproj or .vbproj) for them without using visual studio.So that I could be able to generate and compile the project on the enviroments where Visual Studio.Net is not installed.

Thanks and Regards,
Anubhav Jain
MTS
Persistent Systems Pvt. Ltd.
Ph:+91 712 2226900(Off) Extn: 2431
Mob : 094231 07471
www.persistentsys.com
Persistent Systems -Software Development Partner for Competitive Advantage. Persistent Systems provides custom software product development services. With over 15 years, 140 customers, and 700+ release cycles experience, we deliver unmatched value through high quality, faster time to market and lower total costs.



Mar 16 '06 #1
8 4926
Hello,

Take a look at the Microsoft.Build namespace!
There you will find a lot (!!!) of nice features. I've used it to
traverse and insert nodes to the project file. It works and it is easy
to use!!

Look at, for examle, Microsoft.Build.BuildEngine in msdn

Regards
/Magnus

Mar 16 '06 #2
Hi,
As I am generating the source files using CodeDOM so I dont have the
project file and which I want to generate for those source files.
Regards
Anubhav
"SunYour" <su*****@hotmail.com> wrote in message
news:11*********************@i40g2000cwc.googlegro ups.com...
Hello,

Take a look at the Microsoft.Build namespace!
There you will find a lot (!!!) of nice features. I've used it to
traverse and insert nodes to the project file. It works and it is easy
to use!!

Look at, for examle, Microsoft.Build.BuildEngine in msdn

Regards
/Magnus

Mar 16 '06 #3
Hi,

I think the usual csc/vbc compiler will be enough, if it is a simple
c#/vb file
It doesnt require project to compile the class into dll

Kalpesh

Mar 16 '06 #4
Hello,

You can create a new project file as well, not only modifying them.
If you do not explicitly want to have a project file, use the csc/vbc
compiler.

Example from msdn:

using System;
using System.Collections.Generic;
using System.Text;

using Microsoft.Build.BuildEngine;

namespace AddNewItem
{
class Program
{
/// <summary>
/// This code demonstrates the use of the following methods:
/// Engine constructor
/// Project constructor
/// Project.LoadFromXml
/// Project.Xml
/// BuildItemGroupCollection.GetEnumerator
/// BuildItemGroup.GetEnumerator
/// BuildItem.Name (get)
/// BuildItem.Include (set)
/// BuildItem.GetMetadata
/// BuildItem.SetMetadata
/// BuildItemGroup.RemoveItem
/// BuildItemGroup.AddNewItem
/// </summary>
/// <param name="args"></param>
static void Main(string[] args)
{
// Create a new Engine object.
Engine engine = new Engine(Environment.CurrentDirectory);

// Create a new Project object.
Project project = new Project(engine);

// Load the project with the following XML, which contains
// two ItemGroups.
project.LoadXml(@"
<Project
xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>

<ItemGroup>
<Compile Include='Program.cs'/>
<Compile Include='Class1.cs'/>
<RemoveThisItemPlease Include='readme.txt'/>
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include='Strings.resx'>

<LogicalName>Strings.resources</LogicalName>
<Culture>fr-fr</Culture>
</EmbeddedResource>
</ItemGroup>

</Project>
");

// Iterate through each ItemGroup in the Project. There
are two.
foreach (BuildItemGroup ig in project.ItemGroups)
{
BuildItem itemToRemove = null;

// Iterate through each Item in the ItemGroup.
foreach (BuildItem item in ig)
{
// If the item's name is "RemoveThisItemPlease",
then
// store a reference to this item in a local
variable,
// so we can remove it later.
if (item.Name == "RemoveThisItemPlease")
{
itemToRemove = item;
}

// If the item's name is "EmbeddedResource" and it
has a metadata Culture
// set to "fr-fr", then ...
if ((item.Name == "EmbeddedResource") &&
(item.GetMetadata("Culture") == "fr-fr"))
{
// Change the item's Include path to
"FrenchStrings.fr.resx",
// and add a new metadata Visiable="false".
item.Include = @"FrenchStrings.fr.resx";
item.SetMetadata("Visible", "false");
}
}

// Remove the item named "RemoveThisItemPlease" from
the
// ItemGroup
if (itemToRemove != null)
{
ig.RemoveItem(itemToRemove);
}

// For each ItemGroup that we found, add to the end of
it
// a new item Content with Include="SplashScreen.bmp".
ig.AddNewItem("Content", "SplashScreen.bmp");
}

// The project now looks like this:
//
// <?xml version="1.0" encoding="utf-16"?>
// <Project
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
// <ItemGroup>
// <Compile Include="Program.cs" />
// <Compile Include="Class1.cs" />
// <Content Include="SplashScreen.bmp" />
// </ItemGroup>
// <ItemGroup>
// <EmbeddedResource
Include="FrenchStrings.fr.resx">
// <LogicalName>Strings.resources</LogicalName>
// <Culture>fr-fr</Culture>
// <Visible>false</Visible>
// </EmbeddedResource>
// <Content Include="SplashScreen.bmp" />
// </ItemGroup>
// </Project>
//
Console.WriteLine(project.Xml);
}
}
}

/Magnus

Mar 16 '06 #5
Hello Anubhav,

You need .NET SDK to compile files. This SDK includes csc and vbc that allow
u to compile your app and create solution files
AJ> Hi,
AJ>
AJ> I am having few .net source files(.cs or .vb) and I want to
AJ> dynamically generate the corresponding .net project file(.csproj or
AJ> .vbproj) for them without using visual studio.So that I could be
AJ> able to generate and compile the project on the enviroments where
AJ> Visual Studio.Net is not installed.
AJ>
AJ> Thanks and Regards,
AJ> Anubhav Jain
AJ> MTS
AJ> Persistent Systems Pvt. Ltd.
AJ> Ph:+91 712 2226900(Off) Extn: 2431
AJ> Mob : 094231 07471
AJ> www.persistentsys.com
AJ> Persistent Systems -Software Development Partner for Competitive
AJ> Advantage. Persistent Systems provides custom software product
AJ> development services. With over 15 years, 140 customers, and 700+
AJ> release cycles experience, we deliver unmatched value through high
AJ> quality, faster time to market and lower total costs.
---
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 16 '06 #6
Anubhav,
In addition to the other commetns:

A .net project file(.csproj or .vbproj) is simply an XML file, that adheres
to a specific schema, you could use XmlTextWriter (or XmlDocument if you
like, or even StreamWriter) to create the file. I have not looked into the
Microsoft.Build namespace far enough to see if creating entire project files
is possible...

For information on how MS Build works see:

MS Build
http://msdn2.microsoft.com/en-us/lib...a5(VS.80).aspx

Pay particular attention to:
http://msdn2.microsoft.com/en-us/lib...68(VS.80).aspx
For reference information see:

MS Build reference:
http://msdn2.microsoft.com/en-us/library/0k6kkbsd.aspx
Generally what I would do is look at a couple of existing .csproj & .vbproj
files to get a feel of the layout, then write my .csproj or .vbproj
generator to match that.

Here is the start of a .vbproj generator:

Private Sub CreateVBProject()
Const ns As String =
"http://schemas.microsoft.com/developer/msbuild/2003"
Dim output As XmlWriter = XmlWriter.Create("Sample.vbproj")
'<?xml version="1.0" encoding="utf-8"?>
output.WriteStartDocument()
'<Project DefaultTargets="Build"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
output.WriteStartElement("Project", ns)
' <PropertyGroup>
output.WriteStartElement("PropertyGroup", ns)
' <Configuration Condition=" '$(Configuration)' == ''
">Debug</Configuration>
output.WriteStartElement("Configuration", ns)
output.WriteAttributeString("Condition", " '$(Configuration)' == ''
")
output.WriteString("Debug")
output.WriteEndElement() ' Configuration
' <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
' <ProductVersion>8.0.50727</ProductVersion>
' <SchemaVersion>2.0</SchemaVersion>
' <ProjectGuid>... this appears to be unique to a project
....</ProjectGuid>
' <OutputType>Exe</OutputType>
' <StartupObject>Sample.MainModule</StartupObject>
' <RootNamespace>Sample</RootNamespace>
' <AssemblyName>Sample</AssemblyName>
' <MyType>Console</MyType>
' </PropertyGroup>
output.WriteEndElement() ' PropertyGroup

output.WriteStartElement("PropertyGroup", ns)
' <PropertyGroup Condition=" '$(Configuration)|$(Platform)' ==
'Debug|AnyCPU' ">
' <DebugSymbols>true</DebugSymbols>
' <DebugType>full</DebugType>
' <DefineDebug>true</DefineDebug>
' <DefineTrace>true</DefineTrace>
' <OutputPath>bin\Debug\</OutputPath>
output.WriteElementString("OutputPath", ns, "bin\Debug\")
' <DocumentationFile>Sample.xml</DocumentationFile>
'
<NoWarn>42016,41999,42017,42018,42019,42032,42036, 42020,42021,42022</NoWarn>
' </PropertyGroup>
' <PropertyGroup Condition=" '$(Configuration)|$(Platform)' ==
'Release|AnyCPU' ">
' <DebugType>pdbonly</DebugType>
' <DefineDebug>false</DefineDebug>
' <DefineTrace>true</DefineTrace>
' <Optimize>true</Optimize>
' <OutputPath>bin\Release\</OutputPath>
' <DocumentationFile>Sample.xml</DocumentationFile>
'
<NoWarn>42016,41999,42017,42018,42019,42032,42036, 42020,42021,42022</NoWarn>
' </PropertyGroup>
output.WriteEndElement() ' PropertyGroup

' <ItemGroup>
' <Reference Include="System" />
' <Reference Include="System.Data" />
' <Reference Include="System.Deployment" />
' <Reference Include="System.Xml" />
' </ItemGroup>
' <ItemGroup>
' <Import Include="Microsoft.VisualBasic" />
' <Import Include="System" />
' <Import Include="System.Collections" />
' <Import Include="System.Collections.Generic" />
' <Import Include="System.Data" />
' <Import Include="System.Diagnostics" />
' </ItemGroup>

' <ItemGroup>
output.WriteStartElement("ItemGroup", ns)
' <Compile Include="MainModule.vb" />
For Each file As String In IO.Directory.GetFiles("Processors",
"*.vb")
output.WriteStartElement("Compile", ns)
output.WriteAttributeString("Include", file)
output.WriteEndElement() ' Compile
Next
' <Compile Include="My Project\AssemblyInfo.vb" />
' <Compile Include="My Project\Application.Designer.vb">
' <AutoGen>True</AutoGen>
' <DependentUpon>Application.myapp</DependentUpon>
' </Compile>
' <Compile Include="My Project\Resources.Designer.vb">
' <AutoGen>True</AutoGen>
' <DesignTime>True</DesignTime>
' <DependentUpon>Resources.resx</DependentUpon>
' </Compile>
' <Compile Include="My Project\Settings.Designer.vb">
' <AutoGen>True</AutoGen>
' <DependentUpon>Settings.settings</DependentUpon>
' <DesignTimeSharedInput>True</DesignTimeSharedInput>
' </Compile>
' </ItemGroup>
output.WriteEndElement() ' ItemGroup

' <Import Project="$(MSBuildBinPath)\Microsoft.VisualBasic.t argets"
/>
output.WriteStartElement("Import", ns)
output.WriteAttributeString("Project",
"$(MSBuildBinPath)\Microsoft.VisualBasic.targe ts")
output.WriteEndElement() ' Import

' <!-- To modify your build process, add your task inside one of
the targets below and uncomment it.
' Other similar extension points exist, see
Microsoft.Common.targets.
' <Target Name="BeforeBuild">
' </Target>
' <Target Name="AfterBuild">
' </Target>
' -->
'</Project>
output.WriteEndElement() ' Project
output.WriteEndDocument()
output.Close()
End Sub
--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"Anubhav Jain" <an**********@persistent.co.in> wrote in message
news:OK**************@TK2MSFTNGP11.phx.gbl...
Hi,

I am having few .net source files(.cs or .vb) and I want to dynamically
generate the corresponding .net project file(.csproj or .vbproj) for them
without using visual studio.So that I could be able to generate and compile
the project on the enviroments where Visual Studio.Net is not installed.

Thanks and Regards,
Anubhav Jain
MTS
Persistent Systems Pvt. Ltd.
Ph:+91 712 2226900(Off) Extn: 2431
Mob : 094231 07471
www.persistentsys.com
Persistent Systems -Software Development Partner for Competitive Advantage.
Persistent Systems provides custom software product development services.
With over 15 years, 140 customers, and 700+ release cycles experience, we
deliver unmatched value through high quality, faster time to market and
lower total costs.


Mar 17 '06 #7
The "default" path for the project file definition:

C:\Program Files\Microsoft Visual Studio 8\Xml\Schemas\1033\MSBuild

Microsoft.Build.Core.xsd and
Microsoft.Build.Commontypes.xsd
It looks like the project files for cs and vb are the same in the 2005
edition...

/Magnus

Mar 20 '06 #8
SunYour,
Yes they both follow the same schema. The articles I mentioned point out the
similarities & differences.

Looking at it, I think I would favor Microsoft.Build namespace as you
originally mention over "rolling my own" writer as I mentioned. However I
find knowing both methods beneficial...
The major difference is that cs imports a cs specific targets file, while vb
imports a vb specific targets file. Both targets files import a common
targets file...

For example, vb has this import statement:

<Import Project="$(MSBuildBinPath)\Microsoft.VisualBasic.t argets" />

While cs has this import statement:

<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.target s" />

If you look at the above files, they both import:

<Import Project="Microsoft.Common.targets" />

Plus defines the task to compile VB files (verses the task to compile CS
files in the CSharp targets file).

The above targets files are found in the same folder as the framework,
normally C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727

--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"SunYour" <su*****@hotmail.com> wrote in message
news:11**********************@t31g2000cwb.googlegr oups.com...
| The "default" path for the project file definition:
|
| C:\Program Files\Microsoft Visual Studio 8\Xml\Schemas\1033\MSBuild
|
| Microsoft.Build.Core.xsd and
| Microsoft.Build.Commontypes.xsd
|
|
| It looks like the project files for cs and vb are the same in the 2005
| edition...
|
| /Magnus
|
Mar 20 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Susan Baker | last post by:
Hi, I am (trying) to compile some code I downloaded from the internet. The sources contain references to header files - using the form : #include <pathname/file> If I change the form to...
1
by: eddie wang | last post by:
How to move around a picture file dynamically in an asp page? Any link to sample code will be great. Thanks. *** Sent via Developersdex http://www.developersdex.com *** Don't just participate...
2
by: Astra | last post by:
Hi All Creating an rss.xml file dynamically via ASP/ADO/DB, but find errors in the file. Don't think it's an ASP prob to be honest. Think its more to do with the fact that the ampersands are...
0
by: orencs | last post by:
Hi, I have a small question in regards to Microsoft Practices Enterprise Library Common: I hope you could help because I have reached a dead end. Is there a way to load the configuration...
9
by: Anubhav Jain | last post by:
Hi, I am having few .net source files(.cs or .vb) and I want to dynamically generate the corresponding .net project file(.csproj or .vbproj) for them without using visual studio.So that I could...
0
by: harish139 | last post by:
hi, i want to create a xml file dynamically, that is i have 2 arrays, i want to run a program to fill that array, if the array size becomes 2KB i want to create a xml file like this ...
1
by: harish139 | last post by:
hi, i want to create a xml file dynamically, that is i have 2 arrays, i want to run a program to fill that array, if the array size becomes 2KB i want to create a xml file like this ...
8
by: miladhatam | last post by:
can i change the size of a file dynamically ? for example have 100 Kb and i want to decrease it to 20 Kb thanks
1
by: mnvk | last post by:
Hi, I need to create a text file dynamically at a specified location when I run my console application. Thanks, mnv.
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.