What settings should be used to get custom ItemTemplates working with .NET Core projects? - asp.net-core

I have a Visual Studio 2017 item template extension that is currently working with ASP.NET projects. It has the following .vstemplate:
<VSTemplate Version="3.0.0" Type="Item" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" xmlns:sdk="http://schemas.microsoft.com/developer/vstemplate-sdkextension/2010">
<TemplateData>
<Name>Angular Component</Name>
<Description>Files for an Angular component</Description>
<RequiredFrameworkVersion>4.5</RequiredFrameworkVersion>
<Icon>AngularComponentTemplate.ico</Icon>
<ProjectType>CSharp</ProjectType>
<ProjectSubType>Web</ProjectSubType>
<NumberOfParentCategoriesToRollUp>1</NumberOfParentCategoriesToRollUp>
</TemplateData>
<TemplateContent>
<ProjectItem ReplaceParameters="true" TargetFileName="$fileinputname$.component.html">base.component.html</ProjectItem>
<ProjectItem ReplaceParameters="true" TargetFileName="$fileinputname$.component.ts">base.component.ts</ProjectItem>
</TemplateContent>
</VSTemplate>
Additionally the VSIX file referencing it has
ItemTemplates\CSharp\Web
set for the "VSIX Sub Path" property of the project.
I cannot, however, get this template to appear in ASP.NET Core projects. I tried using this in the vstemplate:
<ProjectType>DNX</ProjectType>
<TemplateGroupID>SharedDotNetAndDotNetWeb</TemplateGroupID>
(from https://stackoverflow.com/a/38543920/1783619) but it didn't work. In the released version of Visual Stuido 2017, how do I get item templates to appear in .NET core projects?

I had this same issue while creating an item template for pug files.
Here is what I did:
Firstly, I found out how the stock templates are written in:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\ItemTemplates\AspNetCore
This is how my template looks:
<VSTemplate Version="3.0.0" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" Type="Item">
<TemplateData>
<DefaultName>page.pug</DefaultName>
<Name>Pug File</Name>
<Description>This is a basic pug file template (previously Jade)</Description>
<ProjectType>CSharp</ProjectType>
<TemplateGroupID>AspNetCore</TemplateGroupID>
<TemplateID>AspNetCore.Pug</TemplateID>
<NumberOfParentCategoriesToRollUp>2</NumberOfParentCategoriesToRollUp>
<Icon>__TemplateIcon.ico</Icon>
<PreviewImage>__PreviewImage.ico</PreviewImage>
<SortOrder>10</SortOrder>
<ShowByDefault>false</ShowByDefault>
</TemplateData>
<TemplateContent>
<References />
<ProjectItem ReplaceParameters="true">page.pug</ProjectItem>
</TemplateContent>
</VSTemplate>
Areas to pay attention to:
ProjectType, TemplateGroupId, TemplateId(make up your own) and NumberOfParentCategoriesToRollUp
I wanted my template to show up mainly in the "Content" category, where the HTML and CSS type templates were so I placed my zip file in
Visual Studio 2017\Templates\ItemTemplates\Visual C#\AspNetCore\Web\Content
I had to create a few directories (AspNetCore\Web\Content) to get this structure.
Then the setting "NumberOfParentCategoriesToRollUp" set to 2 allows the template to display in the "Content" category, but also "roll up" and show in Web and AspNetCore categories.
More info on organization of templates here:
https://learn.microsoft.com/en-us/visualstudio/ide/how-to-locate-and-organize-project-and-item-templates
Then when you are all done, open a visual studio 2017 developer command prompt and type:
devenv /updateconfiguration

The most important thing is
<TemplateGroupID>AspNetCore</TemplateGroupID>
Otherwise you will not see your item template from ASP.NET core project.
Strange thing is that you will see your item template with other project (desktop for example).
Hoping that Microsoft will document or make things easier one day

Related

Web deployment package: Skip files when deploying

I want to create a web deployment package which leaves certain existing directories alone when deploying, e.g. a "logs" folder. Currently the package deletes/overwrites all existing files.
I can exclude the folder by adding extra parameters when executing the foo.deploy.cmd in the package, eg.:
.\foo.deploy.cmd /T """-skip:Directory=\\logs"""
This seem to work. But I can't figure out how to include this configuration in the package itself so it will be applied automatically.
I have a Asp.net Core website on .net framework 4.7. I use Visual studio 2019 with a pubxml publish profile.
I have tried adding MsDeploySkipRules to the pubxml but they don't seem to be passed to the package parameters. I am unsure if MsDeploySkipRules should work with "Web Deploy Package" or only with "Web Deploy"?
Edit: The problem may be related to I'm using Asp.net core. The MsDeploySkipRules seem to be applied in a regular asp.net (added in the generated deploy.cmd script) project but not if I insert the same in an asp.net core project file.
You could try to add the below code in your .csproj file to skip the folder at the time of publishing.
<ItemGroup>
<Content Remove="wwwroot\test\**" />
</ItemGroup>
also ste the delte existing file to true:
ASP.NET Core: Exclude or include files on publish

Is There an EF 6 ObjectContext / EntityObject Code Generator for VB.Net Compatible with VS 2019?

Subject says it all. This is I think what I'm looking for:
EF 6.x EntityObject Generator for VB.NET
but it will not install (apparently since it does not explicitly support VS 2019) - but perhaps there's a way to hack it into installing?
Rename VSIX to zip
Unpack it, go to T\Data\
Copy EntityObjectVB_EF6.zip to %USERPROFILE%\Documents\Visual Studio 2019\Templates\ItemTemplates\Visual Basic\
more info about templates User templates
User templates
If you add a compressed (.zip) file that includes a
.vstemplate file to the user template directory, the template appears
in the new project and new item dialog boxes. By default, user
templates are located in:
%USERPROFILE%\Documents\Visual Studio 2019\Templates\ProjectTemplates
%USERPROFILE%\Documents\Visual Studio 2019\Templates\ItemTemplates
For example, the following directory has user project templates for
C#:
C:\Users\UserName\Documents\Visual Studio 2019\Templates\ProjectTemplates\Visual C#

NuGet package XML documentation not visible in .NET Core 2.2 app

I am using a NuGet package which has an XML documentation file.
But when I include the package in a .NET Core 2.2 app, the comments are not available with IntelliSense.
Is there something I'm missing either in the package or in my app to be able to see the documentation with IntelliSense?
Using VisualStudio 2017, Windows 10.
Update for Clarity
The NuGet package is a .NET Standard 1.3 class library. In Visual Studio when I build the project, I include the options to generate the package and documentation file. In the project file, I see the following PropertyGroup:
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DocumentationFile>C:\Users\[username]\[local path]\CommonEntities\CommonEntities\CommonEntities.xml</DocumentationFile>
</PropertyGroup>
When I open the package, I can see in the lib/netstandard1.3/ directory that CommonEntities.xml is included along with MakanalTech.CommonEntities.dll.
But, I'm wondering why the xml file has dropped the full name from MakanalTech.CommonEntities.xml as it is in the project to just CommonEntities.xml in the package. Maybe this is the cause of the issue?
The issue is then when I include the package as a dependency in another project, none of the XML comments/documentation are visible. So I can't hover over a type to see its description, and if I peek definition none of the comments/documentation are in the definition.
Class Library Product
https://imgur.com/zbE7ngM (can't post images yet)
Peeking at definition from other project:
https://imgur.com/pwmvpX7
Finally found the issue from this post. This seems quite buggy from Visual Studio 2017 not to handle this correctly and automatically.
In the .csproj file, I removed <DocumentationFile>[filepath-to-xml]</DocumentationFile> and added <GenerateDocumentationFile>true</GenerateDocumentationFile>.
I then repacked the library, cleared my nuget cache, and rebuilt the new project where it's included, and now I have all the XML documentation visible.
NuGet package XML documentation not visible in .NET Core 2.2 app
Just like what have you found that "in the lib/netstandard1.3/ directory that CommonEntities.xml is included along with MakanalTech.CommonEntities.dll.", the .xml file in the lib folder, then according to the document From a convention-based working directory:
Only the .dll file will be added as reference, .xml file will be copied to the project folder. That is the reason why the XML documentation not visible in .NET Core 2.2 app.
Besides, since you are using .netstandard project, .xml file will blocked be copied to the project folder automatically by the nuget issue 4837.
To resolve this issue, we have to create the .nuspec file with option contentFiles to include the .xml file and add this file to the project, please check the detail info from other thread.
But if you do not want to manually edit the .nuspec every release, you can use a post-build event to pack the nuget package automatically,like:
nuget pack "$(.NuspecFilePath)\xxx.nuspec"
Or you can add the .xml file to the project manually from the package directly, that package is in the path: C:\Users\<UserName>\.nuget\packages.
Hope this helps.

How to specify a custom parameters.xml when building a Web Deploy package for ASP.NET Core?

Overview
I am building a deployable web package that can be imported into IIS that automatically prompts for settings needed by my ASP.NET Core application. I already created a package that will deploy just fine, except after deploying, I need to manually find/edit my appsettings.json file.
I know this package can include a parameters.xml file that will automatically prompt and fill in my appsettings.json when importing an app into IIS. I have already made a parameters.xml file, and manually added it to my package after building it; it worked as expected. I'd just like to have msbuild automatically add the parameters.xml file to the package for me.
A separate project of mine (ASP.NET MVC 4) already does this. For that, I simply needed to put my parameters.xml in the same folder as my .csproj. I tried doing the same here, but had no luck.
Repro Steps
I created an ASP.NET Core Web Application
Using .NET Framework on ASP.NET Core 1.1
I then went to publish my website
Selected 'Folder' (just to get a template)
I then edited the profile and changed the WebPublishMethod to Package and added the three lines below it.
<DesktopBuildPackageLocation>bin\$(Configuration)\$(MSBuildProjectName).zip</DesktopBuildPackageLocation>
<PackageAsSingleFile>true</PackageAsSingleFile>
<DeployIisAppPath>External</DeployIisAppPath>
I then published one more time. Now I get a WebDeploy package that I can deploy to IIS.
Great! but...
I'd like to customize the parameters.xml.
For previous projects, I was able to add a parameters.xml file to my project root, and VS/msbuild would automatically add it to my published package. This currently works for a different project using ASP.NET MVC 4.
So, I tried the same thing for this project. First I added a settings.json with a very simple setting:
{
"SettingName": ""
}
Then I added a parameters.xml file that I know works to my project root. (If I manually replace the parameters.xml file in Sample.zip package, it correctly prompts and replaces my setting when deploying)
<parameters>
<parameter name="IIS Web Application Name" value="External" tags="IisApp">
<parameterEntry kind="ProviderPath" scope="IisApp" match="^c:\\users\\joshs\\documents\\visual\ studio\ 2017\\Projects\\Sample\\Sample\\obj\\Release\\net461\\win7-x86\\PubTmp\\Out\\$" />
</parameter>
<parameter name="Setting Name" description="Enter a custom app setting" defaultValue="Default Setting Value">
<parameterEntry kind="TextFile" scope="obj\\Debug\\net461\\win7-x86\\PubTmp\\Out\\appsettings\.json$" match="(?<=\"SettingName\"\s*:\s*\")[^\"]*" />
</parameter>
</parameters>
Again, I right click and Publish once more. This time with the parameters.xml file.
I expect the Sample.zip to contain the parameters.xml that I added to my project root, but it does not. It is the exact same as from my original publish.
Question
During the build process when creating a web deploy package, how do you include custom settings in the parameters.xml?
I have already tried this...
I already looked at https://stackoverflow.com/a/46338042/2494785, but with no luck, though my command differed slightly from the original poster.
PS C:\Users\joshs\Documents\Visual Studio 2017\Projects\Sample> & 'C:\Program Files (x86)\Microsoft Visual Studio\2017\E
nterprise\MSBuild\15.0\Bin\MSBuild.exe' .\Sample.sln /t:Sample /p:DeployOnBuild=true /p:PublishProfile=FolderProfile /p:
ProjectParametersXMLFile="C:\Temp\parameters.xml"
I was able to solve this from peteawood's comment from an issue posted on GitHub.
https://github.com/aspnet/websdk/issues/201#issuecomment-349990389
In ASP.NET Core 2.0+ you can add the following to your .csproj
<Project Sdk="Microsoft.NET.Sdk.Web">
.
.
<Target Name="AddMoreParameters" AfterTargets="_CreateParameterFiles">
<Copy SourceFiles="Parameters.xml" DestinationFiles="$(_MSDeployParametersFilePath)" />
</Target>
</Project>
SourceFiles should point to the location of your parameters.xml file from the perspective of the .csproj file. My parameters.xml is found in the same directory as my project file.
I believe I can just pass parameters via cmd-line as properties for msbuild.
It's not fully what you asked for I understand.
For example, in the following command I'm passing DeployIisAppPath property:
dotnet publish /p:WebPublishMethod=Package /p:DeployIisAppPath=mysite/myapp /p:PublishProfile=rnddev03-core-dev
and in the output folder we'll get xxx.SetParameters.xml file with:
<parameters>
<setParameter name="IIS Web Application Name" value="mysite/myapp" />
</parameters>

Visual Studio 2010 SharePoint Replaceable Parameter is not being replaced

I'm creating a custom WCF service for deployment inside SharePoint 2010 following the instructions on the SharePoint Bits Blog.
As step 3 says, I am building contents of my .SVC file. Note that this is a blank text file with a .SVC extension, and I have manually entered the text into this file.
<%# ServiceHost
Language="C#"
Factory="...(omited for length)..."
Service="Assembly.MyService, $SharePoint.Project.AssemblyFullName$" %>
The $SharePoint.Project.AssemblyFullName$ is a replaceable parameter that visual studio is supposed to replace with the strong name of the assembly built by my project when the solution is packaged.
The problem is that the replaceable parameter isn't getting replaced during the package step. My project also includes a visual web part (the .webpart file of which contains the same replaceable parameter) that is having its replaceable parameter replaced correctly.
how do I get the replaceable parameter in my .SVC file to replace during the package step?
Preferred option is to add a new PropertyGroup to the Project.csproj file manually in Notepad (aaargh), but then at least it works on a fresh checkout / other dev pc as well:
<PropertyGroup>
<TokenReplacementFileExtensions>svc</TokenReplacementFileExtensions>
</PropertyGroup>
Have you added .SVC file extension to this list:
Although tokens can theoretically be
used by any file that belongs to a
SharePoint project item included in
the package, by default, Visual Studio
searches for tokens only in package
files, manifest files, and files that
have the following extensions:
XML
ASCX
ASPX
Webpart
DWP
These extensions are defined by the
element in the
Microsoft.VisualStudio.SharePoint.targets
file, located in the …\\MSBuild\Microsoft\VisualStudio\v10.0\SharePointTools
folder.
You can, however, add additional file
extensions to the list. To do this,
add a
element to any PropertyGroup in the
SharePoint project file that is
defined before the of the
SharePoint targets file.