Creating a Visual Studio project from command line or powershell - c#

I have a quite huge solution and I've to perform some maintenance (creating test classes for whole projects and so on) and I was wondering if it's possible with powershell or vscode to create projects automatically. I've just followed this link and tried to use the IVSSolution interface from powershell but with no luck. Is there a working and simplier solution?

While, I'm not sure your requirements, I think what you should be really looking for is Project Templates.
This blog explains the process of creating a project template in details. Or, You can, create a project template using PowerShell.

Related

Create Solution/Project programmatically without Visual Studio

I would like to create a Visual Studio Solution and a C# Project programmatically, but without a instance of Visual Studio installed on the machine.
Scenario
I am trying to build a "engine" that will read some metadata in a SQL database and transform them into a UI. The database will be maintained by another people with a Web or WCF interface and I want the Server Application frequently (by schedule or pressing a button) use this informations to create autommaticaly a new version of the software (create solution -> project -> build -> create deployment).
So, I searched about programmatically create Solution and I found only the Automation Model in VS, it's about use an Add-In Project and this don't serves for my propose.
Perhaps I was a little confused in my explanation, so ask me more especific details, so I can be more accurate :)
Thanks for help
I think generating the solution is a little extreme.
The solution file structure hasn't changed much since 2005 http://msdn.microsoft.com/en-us/library/bb165951(v=VS.80).aspx, and there are a few projects trying to automate their generation, like Premake https://bitbucket.org/premake.
However, the kind of scenario you describe, might be I believe (better?) adressed with t4 templates http://msdn.microsoft.com/en-us/library/vstudio/bb126445.aspx, or only project file generation.
What you are describing is possible to do in C# Windows app but tedious and difficult. I remember seeing VB6.0 app like that but here i would suggest you look into WPF. Still it's C# programming but WPF can load dynamically a "window" from a string or a file if you want.

Call AnkhSVN commands in C#

Is there a way that I can call the same commands that Ankh SVN uses, within C# code?
For example, can I call the same functionality that adds a solution to a subversion from code?
I am writing Visual Studio addin that will allow me to reuse a solution template, rather than having to recreate the same basic structure again and again.
Is there a list of macros or similar that AnkhSVN would map its commands to - i.e. Add solution to subversion?
I have looked around for templates or addins that would do the job for me but have decided to make my own, so am not looking for links to any other templates or addins.
Edit: I think that I may also be able to use this._applicationObject in my addin to add my solution to subversion as I would if I were manually doing so using Visual Studio.
You could use SharpSvn to work with Subversion directly from within your C# extension.

How can I create Setup package for wpf 4.5 application using some script

I need to create install-able setup via scripting for my WPF application. I don't know where to start and what is best way to do this. Please help.
You can either:
Use the built in setup project type in Visual Studio to create an MSI installer
Tutorials
Use something like NSIS or WIX. I use NSIS for all of my apps, both have learning curves and NSIS is fairly easily skinnable.
NSIS Examples
WIX Examples
Consider using Inno Setup ▶ http://www.jrsoftware.org/isinfo.php
It is free and also provides powerful script to make a installer package.
Agree with Echilon.
I would like to add that Inno Setup is also a very good solution to try.
IMHO WIX is much harder to understand and to manage than alternatives, for little projects it's not the best option.

Generate c# solution template

I want to create a VS2010 c# solution template generator and I'm looking for free/open tools to achieve this.
An example of what I'm trying to do is a winform application takes project name, namespace and database connectionstring and produce a c# customized solution with my custom classes, namespace and references.
I found those:
EnvDTE
Code Generation and T4 Text Templates
Is this the right way to do this? Do you know better tools?
You need to look at project templates. Normally you only get prompted for a project name (used as the solution name as well if creating a solution at the same time).
However the project template system can run code (as seen with C++ and ASP.NET MVC Projects).
There is a lot of information in the VS SDK, but you might find examining project templates that launch wizards useful to isolate the useful bits of documentation.

Why would I want to continue to use Nant when MSBuild is available?

I have seen the prior questions and answers. In that one question, the original poster asked a followup question:
what are the compelling reasons to use msbuild? are there cons?
I didn't see the answer to that. I'd like to know the converse, too. What are the compelling features of Nant?
I think, for nant, cross-platform is big. For msbuild, it is the currency and integration with Visual Studio. Does this sound right? Anything else?
EDIT/Added: anyone have a feature list comparison? Someone said "nant has more features out of the box." Which ones?
Would it make sense to combine these projects, combine efforts so as to benefit mutually? Has anyone asked MS if they'd be willing to contribute msbuild to the community, like WiX? What are the chances?
EDIT2: I just found this prior discussion, not sure why I couldn't find it before.
Nant has more features out of the box, but MSBuild has a much better fundamental structure (item metadata rocks) which makes it much easier to build reusable MSBuild scripts.
MSBuild takes a while to understand, but once you do it's very nice.
Learning materials:
Inside the Microsoft Build Engine: Using MSBuild and Team Foundation Build
by Sayed Ibrahim Hashimi (Jan, 2009)
Deploying .NET Applications: Learning MSBuild and ClickOnce
by Sayed Y. Hashimi (Sep, 2008)
I simply find NAnt easier to use. I dare say this is partly due to my background in Ant, but I found building a NAnt file for Protocol Buffers to be a much simpler job than building an MSBuild file for MiscUtil. (Even now there are things in the MiscUtil build which I'd like to include but can't - it seems ridiculously hard to dump the output of a task to a text file, IIRC.) The concepts are simpler, and there seem to be fewer gotchas in terms of when file collections are evaluated etc.
I currently like using a setup which I previously thought was really silly - I use NAnt for my "main" build file, but invoke MSBuild to do the actual "compile my .NET project" step. The idea of having two build systems for the same project is abhorrent, but I basically don't treat the MSBuild part as a full build system - it's just an easy way of compiling, and I never need to manually examine the project file. (I only interact with it via Visual Studio.) I've been able to evolve my Protocol Buffers build very easily this way, and I doubt I'd have had the same experience if I'd used MSBuild.
Soon I'm going to try building it all with Mono (when 2.4 is released - until then there are showstoppers in gmcs) at which point we'll see how portable the strategy is...
You would continue using nant because you are already using it. If you were using msbuild, and wanted to know why would you switch to nant, then the answer is theres no real reason to switch. At least you know msbuild isnt going anywere, nant hasnt been updated since december 2007.
Considering that NAnt is based off Ant for Java, that there might be reason enough to stick with it. Other build tools are based off Ant - Phing is one, for PHP. When I started using that tool, I picked it up in no time since I was already familiar with NAnt.
We use a hybrid approach because we started on NANT before MS-Build was available. However MS-Build cna do parallel buids on projects that are not dependent which can in the right circumstances reduce your build times significantly. Leaving NANT to interact with SVN, deployment and just having MS-build do compilation cut our build times by about 45% YMMV depending on how you structure your sln.
Some points that came to mind:
you must use msbuild if you are working with Windows Workflow Foundation (compiling *.xoml files, probably this is also true for WPF)
if you are using wix for building setup .msi file you can use VisualStudio or msbuild to compile wix scripts (in case of error VS can jump to problematic line in wix script)
msbuild allows you to have build environment as much similar to development/Visual Studio environment (for example when building with msbuild postbuild events are executed, you don't have to manually maintain a list of *.cs files to csc task, ...)
Where I work we are currently using NAnt scripts with msbuild task from NAntContrib.

Categories