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/library/wea2sca5(VS.80).aspx
Pay particular attention to:
http://msdn2.microsoft.com/en-us/library/ms171468(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.targets"
/>
output.WriteStartElement("Import", ns)
output.WriteAttributeString("Project",
"$(MSBuildBinPath)\Microsoft.VisualBasic.targets")
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
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.