Code publish to folder not copying EmailTemplate folder .NET 6 - asp.net

I have upgraded my Web API project from ASP.NET Framework to .NET 6. We were using the publish to folder option before publishing the code to IIS directory and it was copying EmailTemplate folder fine which has html files for emails. But as we upgraded to .NET6 the EmailTemplate folder is not copied and I have to manually copy/paste it every time. Anyone else faced the same issue or any suggestion will be appreciated.

I have added this to my project file and copied it to the folder.
<ItemGroup>
<None Include="EmailTemplates\**">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

Related

.NET Core Console include specific folder when publishing

I want to include a specific folder and its subdirectories when I publish the .NET Core Console application. I added the following code in the Properties/PublishProfiles/FolderProfile.pubxml file.
<ItemGroup>
<_CustomFiles Include="$(MSBuildProjectDirectory)/../Templates/**/*" />
<DotNetPublishFiles Include="#(_CustomFiles)">
<DestinationRelativePath>Templates/%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath>
</DotNetPublishFiles>
</ItemGroup>
but this code does not work.
The weird thing is that, those code works when I publish my .NET Core Web API project.
Is there any difference for the configuration between Web API and .NET Core Console?
What i actually do is to update the item's build profile which allows the respective folder and the contents included in the publish directory as well.
Something like this below appears in the .csproj file
<ItemGroup>
<None Update="depends\Bitmap1.bmp">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

.net core build produces localization folders

I have a web asp.net solution that is using .net core 2.0. I am building it using the command:
dotnet publish MySolution.sln --configuration release --output d:\test_output
But when I check the output folder, I'm seeing a lot of localization folders, as you can see in the image bellow:
Is there a way to publish the code without generating these folders?
For the projects using ASP.NET Core 3.1, add this line to your *.csproj file:
<PropertyGroup>
<SatelliteResourceLanguages>en</SatelliteResourceLanguages>
</PropertyGroup>
The source of the answer in this post: Disable Dll Culture Folders on Compile.
The solution provided by #Igor.K worked for my API project, but for the ASP.NET Core MVC website in my solution, I had to make a minor change.
Try adding the line below to your .csproj file.
<PropertyGroup>
<ResourceLanguages>en</ResourceLanguages>
</PropertyGroup>
You can edit this file by right-clicking your project and selecting "Unload Project". Then, when you right-click again you will be able to edit the .csproj file. Make sure you reload the project when you're finished though.
So, if SatelliteResourceLanguages doesn't solve your problem, ResourceLanguages might do the trick.
[in net 5.0] All above solutions didn't work for me.
Out of despair I added:
<PropertyGroup>
<SatelliteResourceLanguages>en-US;en</SatelliteResourceLanguages>
</PropertyGroup>
and it worked, absolutely no idea why
On the .csproj file, you look for "Microsoft.VisualStudio.Web.CodeGeneration.Design" Package reference and add the property ExcludeAssets="All"
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.1" ExcludeAssets="All" />
Here is the reference: Disable Dll Culture Folders on Compile
Neither the SateliteResourceLangauges nor the ResourceLangauges solutions worked for me. In my case the files were being generated by the following nuget:
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" ExcludeAssets="All" />
Affixing ExcludeAssets="All" to it as shown above resolved the issue.

BundlerMinifierCore files are not copied on dotnet publish

I had an ASP.NET Core 1.1 application, which was upgraded from Visual Studio 2015 using project.json to Visual Studio 2017 with the MsBuild csproj standard. The app is deployed to a docker container on linux, where the official images from microsoft are used. BundlerMinifier were missing. But only on docker, not in Visual Studio 2017 and not using dotnet publish on Windows 10.
I found out, that the bundles were generated. But in the wwwroot folder of the solution, not in the publish output folder (passed by --output to dotnet publish). Lets say, I have /app where my VS solution is located in the docker container. Now I run dotnet publish --output /app/output. My bundled files are now in /app/src/{projectName}/wwwroot instead of /app/output/wwwroot where I need them.
I use relative paths in the bundleconfig.json like this:
[
{
"minify": { "enabled": false },
"outputFileName": "wwwroot/site.min.css",
"inputFiles": [
"wwwroot/lib/my-input-file.css"
]
}
]
To create the bundle, I have the following publishing scripts in my csproj file
<Target Name="PrepublishScript" BeforeTargets="PrepareForPublish">
<Exec Command="bower install" />
<Exec Command="dotnet bundle" />
</Target>
I'm not very familar with MsBuild. But according to some researchs, the following lines seems responsible to copy files to the output directory (like wwwroot)
<ItemGroup>
<None Update="wwwroot\**\*;Views\**\*.cshtml;Areas\**\*.cshtml">
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</None>
</ItemGroup>
Since wwwroot is already included here and the copying of other files like Views works, I thought there is an issue about execution ordner. Something like MsBuild copy the files before MsBuild is publishing them. But this seems not possible from the logic, since this is done before PrepareForPublish target, which is - according to Microsoft docs - the right way.
That's because you don't include the files in the wwwroot.
<ItemGroup>
<None Update="wwwroot\**\*;Views\**\*.cshtml;Areas\**\*.cshtml">
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</None>
</ItemGroup>
wwwroot\**\* will only copy over the files in subfolders of wwwroot (at least this was still the case with the old project.json structure), but your css file is in wwwroot/site.min.css. So either move them to wwwroot/css/site.min.css. Or easier: Just publish the copy over the whole wwwroot folder (and keep your libs files outside of wwwroot, like in bower_modules or npm_modules):
Also I'm not sure of <None> is the right tag for it. In my project's csproj there is only <None Include="App.config" /> and the files I copy over are in <Content>, like below
<ItemGroup>
<None Include="App.config" />
<Content Update="wwwroot;Views;Areas;appsettings.json;web.config">
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
</ItemGroup>
As you shouldn't have any unrelated files in Views and Areas it's easier to copy over the whole folders too.

Convert .Net Core to .Net Framework

I have a .Net Core project web project, and for various reasons want to convert it to a .Net Framework project.
Is there an easy way to do this, or do I have to start again and import the code from the previous projects
I have loaded core project to the VS 2017 RC Community and open *.csproj in text editor.
Just delete teg
<RuntimeFrameworkVersion>
and replace
<TargetFramework>netcoreapp1.1</TargetFramework>
to
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
And after all in project properties set to any another framework and reset back (VS reload and repair *.csproj file).
This worked for me in VS2017:
Start with .net core web project template.
Edit *.csproj so it looks like this:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net472</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore" Version="2.1.3" />
<PackageReference Include="Microsoft.AspNetCore.CookiePolicy" Version="2.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.1.1" />
<PackageReference Include="Microsoft.AspNetCore.HttpsPolicy" Version="2.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.RazorPages" Version="2.1.2" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.1.1" />
</ItemGroup>
</Project>
Save and close.
Try running project.
The PackReferences is just the NuGet files, and you can add them through the GUI if the versions are different from mine above.
There's lots of similar answers here, but I didn't see one that was quite what I ended up doing, so I'd like to leave this here just in case someone else is in the same shoes.
Just to be clear, my project was a console program. So, if you're trying to use this answer for something else, your mileage may vary.
In your .csproj file, inside of the <PropertyGroup></PropertyGroup> tag, modify <TargetFramework> to reflect the following:
<TargetFramework>net461</TargetFramework>
Now, in this example, I was using v4.6.1. I can only assume that you'll plug in your version behind the word "net", without the periods. Good luck!
None of the answers here worked for me. In .Net Core 2 the project.json file no longer exists. However, I did solve this problem using the following steps.
1) I removed all nuget packages from my existing project.
2) I created a separate .net core web app project, targeting .net 4.61. This was to get the default nuget packages.
3) I edited the temporary project's .csproj file, copied all the PackageReference nodes inside ItemGroup, and pasted them into my existing projects .csproj file.
4) Edited the TargetFramework node (inside PropertyGroup) from "netstandard2" to "net461"
I had a few package changes to track down and resolve, but otherwise I was able to run.
In my version of Visual Studio 2017 (15.6.2) after 'Unloading the Project', right-clicking and selecting 'Edit <your project file>, I had to:
Add the node:
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
Delete the nodes:
<TargetPlatformIdentifier>UAP</TargetPlatformIdentifier>
<TargetPlatformVersion Condition=" '$(TargetPlatformVersion)' == '' ">10.0.16299.0</TargetPlatformVersion>
<TargetPlatformMinVersion>10.0.16299.0</TargetPlatformMinVersion>
<ProjectTypeGuids>{A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
There are several steps that you need to do, in order to achieve this.
Firstly right click on the .csproj file and add the following
<TargetFrameworks>netstandard2.0;netcoreapp2.0;net35;</TargetFrameworks>
<RuntimeIdentifiers>win7-x86;win7-x64</RuntimeIdentifiers> <EnableDefaultCompileItems>false</EnableDefaultCompileItems>
Once you have made these changes reload the project and build it.
This will generate the .dll files and Nuget package for this
build in the Debug/Release folder of the project.
Add these .dll to the nuget and access these projects from
nuget.
Try the above steps. This should work.
My .net standard project is relatively simple with few Nuget packages. I just changed
<TargetFramework>netstandard2.0</TargetFramework>
TO
<TargetFramework>**net461**</TargetFramework> under PropertyGroup section of .csproj file and this did the job for me.. Thanks to Brandon Barkley for your answer in the comments.
add below in csproj
<PropertyGroup>
<TargetFrameworks>netcoreapp2.1;net471</TargetFrameworks>
</PropertyGroup>
I had only a handful of source files. For me it worked best by
Closing Visual Studio 2022
Renaming away the solution folder
Creating a new Visual Studio solution of type "WPF App (.NET Framework)" with the original folder name and same project name
Copying all *.xaml. *.xaml.cs and *.cs from the old project to the new, not touching *.sln, *.csproj and *.config.
Project->Add Existing Item… and adding the copied items
Adding all the special references.
That rebuilt all without a complaint.

How is the ExcludeFromBuild itemgroup supposed to work in Web Deployment Projects?

I added an ItemGroup for ExcludeFromBuild items in the PreBuild target in my Web Deployment project:
<ItemGroup>
<ExcludeFromBuild Include="$(SourceWebPhysicalPath)\Test\**\*.*" />
</ItemGroup>
After the build the assembly in the output still contains the compiled classes from the files in ~/Test. That's not what I expected.
Here is a snippet from Using Web Deployment Projects with Visual Studio 2005 on MSDN:
For example, by adding the following
section to a Web
Deployment project, you can exclude
the Test and Images folder from the
build process:
<ItemGroup>
<ExcludeFromBuild Include="$(SourceWebPhysicalPath)\Test\**\*.*"/>
<ExcludeFromBuild Include="$(SourceWebPhysicalPath)\Images\**\*.*"/>
</ItemGroup>
This is useful if you have test code
in the Web site project that should
not be included in the staging or
release builds.
Seems not work that way for me though. Am I missing something obvious?
Never mind, I have found the problem. The ExcludeFromBuild item group is evaluated in the _CopyBeforeBuild target, which is called before the BeforeBuild target.
Doh!

Resources