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>
Related
I have a Blazor server app with a client project. In the client project, I have a bunch of pages and components. Adding a file with the same name as the razor page with the CSS extension worked so far to create scoped CSS files… But somehow not anymore.
I added a new page under the page's folder. Named Historia.razor. Added a Historia.razor.css file in the same folder. Visual Studio understands it nicely and nests the CSS page under the main razor file.
But when compiling and running the app, the styles do not appear. I checked the combined CSS file (MyApp.styles.css) and there are no entries from the Historia.razor.css file. Also checked the styles on the generated page and they don't contain the b-213321 extra ID on the class names.
I checked the project file to ensure the file is not under the "ignore", It is not. This is what the project file looks like:
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Blazored.Toast" Version="3.2.2" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="6.0.3" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="6.0.3" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="6.0.3" />
</ItemGroup>
<ItemGroup>
<Watch Include="**\*.razor" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Shared\VikingBoardGames.Shared.csproj" />
</ItemGroup>
</Project>
Once again, it DOES WORK for other components and pages that I added in the past and follows the same exact folder/naming structure.
Any ideas on what is preventing the CSS to be bundled with the rest?
NOTE: After doing a clean - build -delete .vs folder - restart VS as suggested by Henk Holterman my tags do show the b-312412wgz code. But still, the styles are not applied and the CSS content is not added to the myproject.styles.css file.
I tried also to create a new file, with its CSS file. Exactly the same behavior.
Whenever things don't work as they should, the following steps might help:
Do a Build|Clean Solution
Close VS
In the Solution folder, delete the .vs folder
Reopen the Project and do a Build|Rebuild
and in case of a Web App,
Use Ctrl+F5 to force refresh all files
With the Dev tools (F12), go to the Application tab and clean the Cache and Local storage.
Cross your fingers and try again.
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>
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.
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.
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!