Visual Studio 2017 Project Template + VSIX: Image not included when creating a new project? - visual-studio-2017

Working on my first VS 2017 project template, following these steps:
Created an empty class library project, the project includes an image in the root
Exported template - verified that the .zip file contains the image
Created a VSIX project and added the zip as the project template asset - verified that .vsix contains the image (after renaming it to zip)
After installing VSIX and creating a project from New Project, all seems to be well, except the image is not included in the project, i.e. the file is not there.
If it makes any difference, this is a .NET Core project targeting multiple frameworks (i.e. the image file is not explicitly specified in the project).
The .vstemplate file does contain it as a project item:
<TemplateContent>
<Project TargetFileName="ClassLibrary.csproj" File="ClassLibrary.csproj" ReplaceParameters="true">
<ProjectItem ReplaceParameters="false" TargetFileName="icon.ico">icon.ico</ProjectItem>
</Project>
</TemplateContent>
Any ideas what I may have missed?
Thanks!

In order for items to copy to the template-created project they must also be included in the .csproj file and Visible not hidden.
Is your icon.ico in your .csproj file too?

Related

How to prevent Visual Studio 2017 from adding log files into solution?

I have a C# .Net Core project and when I run this project the executable creates log file in it working directory which is same as project directory (where .csproj and other files are placed)
It is a rolling file, so every day it creates a new file with Date in the file name.
Problem is: Visual Studio adds this files into solution automatically:
How can I prevent this behavior? (This files are already in .tfignore file for TFVC but of course it has no impact on VS behavior).
UPDATE: I can exclude it from project manually but I don't like to do it every day.
I found solution:
Open your .csproj xml file
Add new section:
<ItemGroup>
<None Remove="log*.txt" />
</ItemGroup>
Enjoy you work!

Nuget "Manage Packages" dialog. Project names are mixed up

I've got a Visual Studio 2017 solution with several C# class library projects. On disk they take this structure:
MyProduct
MyCompany
MyCompany.ModuleA
MyCompany.ModuleB
MyCompany.ModuleC
But when I look at them in the "Manage NuGet Packages for Solution, the checkboxes show up in the dialog inconsistently. ModuleC appears strangely. Like this:
MyCompany.ModuleA
MyCompany.ModuleB
MyProduct\MyCompany\MyCompany.ModuleC
Also, whenever I build Module C, it keeps creating the following 3 files in its output /obj folder
- MyCompany.ModuleC.csproj.nuget.g.props
- MyCompany.ModuleC.csproj.nuget.g.targets
- project.assets.json
Neither of the other two modules does this.
I'm trying to understand the reason for the inconsistency and to fix it if I can. I have tried combing through the text of the .csproj files for these various projects but I can't spot any differences that might make this happen. And the raw text of the .SLN file project entry all look consistent for each of the 3 modules.
How does NuGet decide what name to put in the Manage Packages for Solution dialog?
Why is NuGet creating those temporary files in the output folder for Module C but not Module's A or B?
How does NuGet decide what name to put in the Manage Packages for Solution dialog?
It is depends on the NuGet manager type, packages.config or PackageReference.
If the project use packages.config, project name will be put in the Manage Packages for Solution dialog. If the project use PackageReference, project file name and relative path will be put in it. That because NuGet will update the project file .csproj when we install the nuget package with PackageReference. So, in the the Manage Packages for Solution dialog, it shows the relative path+project file name, like ClassLibrary1\ClassLibrary1.csproj.
Why is NuGet creating those temporary files in the output folder for
Module C but not Module's A or B?
That because NuGet with PackageReference controls the msbuild items that are generated for these files into the obj\projectname.csproj.nuget.g.props, obj\projectname.csproj.nuget.g.targets and project.assets.json file.
You can unload your project, check if the project file MyCompany.ModuleCuse the PackageReference, like:
<ItemGroup>
<PackageReference Include="Newtonsoft.Json">
<Version>11.0.2</Version>
</PackageReference>
</ItemGroup>
For some more details, please check this official blog: NuGet is now fully integrated into MSBuild.

Creating visual studio template projects

I created a project template as described here: vs create template When I created a new project using the template, source files haven't added to project. I am using visual studio 2017 community edition. Actually source files (.h and .cpp) are visible in the solution explorer but they are not included in the project folder. So when I try to open them, ide gives me this message: "The document cannot be opened. It has been renamed, deleted or moved."
Is this a bug ? How can I fix it ?
It seems this is a bug. I solved it like this:
Visual studio automatically generates a .zip file containing the template project settings. However in that .zip folder, it doesn't include source files. I manually added every source files to the zip. Then I added fallowing lines to the automatically generated "MyTemplate.vstemplate" file.
<TemplateContent>
<Project File="yourProjectName">
<ProjectItem>source.cpp</ProjectItem>
.
.
.
</Project>
</TemplateContent>
and it worked.

Visual Studio 2015 Project Templates (C++) won't create project file in specific location

I'm trying to find how to create my own VC++ project template with all parameters set up for future development. But suddenly I appeared to stuck at a little problem: VS2015 won't create given structure inside of the project folder.
That's how my directory looks like inside of .zip file used for templating inside of Visual Studio:
Project/%ProjectName%.vcxproj
Project/%ProjectName%.vcxproj.filters
Project/%ProjectName%.vcxproj.user
Src/Main.cpp
MyTemplate.vstemplate
To be precise, it won't place .vcxproj file into the
%created_project_folder%/Project
directory, but directly into
%created_project_folder%/
directory instead, ruining file dependencies specified inside of project file. E.g. "include ../Src/Main.cpp" won't work because it will seek for file in wrong location.
I attached link to my .zip file below.
https://fex.net/#!654242360762
You can try to copy that onto #user#\Documents\Visual Studio XXXX\Templates\ProjectTemplates folder and then create project in VS. Project file will be created on the root instead of custom location.

Visual Studio 2013 export Property Sheets to Template

I am Creating a C++ Project template and using the export template wizard to do it.
I had added a custom property sheet to my template project (the one which am going to export)
on successfully exporting my project template I created a new project using the template, but the project fails to load saying that it can't find the property sheet (it mentions the project directory path and says no such file exists).
I know the same question has been asked before : Exporting .props files in project template VS2012/13
But it has no answer for a year
I even tried including the property sheet as part of the project before exporting. still the same error
Please Help!
Edit:
I even tried manually putting the .props file into the zip archive it still shows the same error.
I think the new project gets loaded before the .props file gets added to the new project directory.
Note : Manually putting the .props file into the new project directory and then reloading the project works. but I don't want to copy paste it every time I create a new project from the template.