Link to home
Start Free TrialLog in
Avatar of packratt_jk
packratt_jkFlag for United States of America

asked on

Solution platform not being created in new Project's platform

I have a solution with a custom solution target (x86).  When I create a new project (.net 2.0 Windows Forms Application), it creates the project file, but only with the 'Any CPU' project target.  The problem here is that if I press F5 to run the app, it doesn't build first (presumably because there is no 'Any CPU' target), which is a pain.  To fix this, I have been going into the configuration manager, finding the new project, and adding a new project target of x86 and clicking the build checkbox.  After that, the project works as expected, building before running on F5 and so-on.

The question - is there a way to automatically have newly created projects with the existing solution targets?
Avatar of packratt_jk
packratt_jk
Flag of United States of America image

ASKER

Really?  25 hours and not even a comment?
ASKER CERTIFIED SOLUTION
Avatar of Dabas
Dabas
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Dabas,

Thank you for your response.  The Project target can be found by viewing the project properties, Build tab, Labeled 'Platform'.

I think your approach of using a template is a good idea though - it will resolve this issue as well as keep future projects consistent.  I have made a new project and exported it as a template, then created a new project from this template.  Most of it works great, but there are a few things I would like to alter that I was hoping can be done in the template itself:

1) I would like the .cs filenames to have a name matching the project.  For example, if I have a project TestApp, than I would like to have file named TestApp.cs, not Template.cs as per the template.

2) I would like the namespace / class names to match as well.  Looking in the template file, I see that there is a '$safeprojectname$' variable (used in AssemblyInfo.cs).  I have tried to alter the .cs files to use this variable instead of the hard-coded names, but when I re-zip the files they are no longer detected by VS.  Also, if i extract the files with WinZip (v 12.0-8252), I get a CRC error.  I am assuming that VS does some non-standard things with the .zip file, and that's why when I re-zip it with winzip VS no longer recognizes it - is there a tool in VS that I should be using instead to re-zip the files?
I figured out the .zip files not being detected problem - I was zipping up the folder - VS expects just the files to be zipped up, not the folder they are in. Works great now, but still have the want to rename the files.
Looks like nobody else is going to comment on this one.  Renaming the files is a whole lot better than what I had to do before, and this approach does resolve the reported issue, so I'm awarding full points to Dabas.

Thanks!
When you export to template, does it not ask you for a name? If you name it TestApp, then the name of the derived project will be TestApp.
You probably gave it the name Template

Dabas
The project I made I named BoilerPlate.  The template I created from the project I named BoilerPlate as well.  After the template was made, I extracted the files and altered them so that the text BoilerPlate would be replaced by the new project name ($safeprojectname$).  After that, I re-zipped the files and copied that zip to the templates directory.  So now, when I make a new project based on that template, the namespace and project name are set to the new project's name (this is the desired behavior).  The only thing that I can't seem to change is the actual file names themselves.  For example, if i create a new project named NewProject based on this template, I will get a NewProject.csproj, as well as the files from the template (BoilerPlate.cs, etc).  Inside the BoilerPlate.cs file, there is a namespace declaration of NewProject, as well as a class named NewProject (this is the desired behavior).  This behavior resolves my initial question, as it does also pull in the project build targets and other project settings (references, etc) in from the template.  The last remaining problem (albeit a small one), is that the I would like the file BoillerPlate.cs to get created and added to the project as NewProject.cs.  This is a simple rename operation, but automating it would be nice.  I've read msdn's documentation, and there doesn't seem to be any support for this in templates (they just splat down the files from the zip), but I thought maybe somebody might know of a loophole in the mechanism.
The solution is not necessarily a time saver, but one I use myself.
You just create two templates:
The project template, with no files in it. Includes your .csproj file only
An item template, which includes your .cs file
Once you have loaded the Project from your project template, you click on Add, New Item, and at the bottom, under templates, you will find your BoilerPlate template, which you can then rename at will.
Well, my base project has four different files in it, so I think I'll just stick with the current implementation which is just to rename the files.  Thanks for the suggestion though (especially post solution-accepted), I'll keep that in mind for future project ideas.