【问题标题】:Bundles not created when using dotnet run in a project with a dotnet bundle task使用 dotnet 在具有 dotnet bundle 任务的项目中运行时未创建捆绑包
【发布时间】:2016-11-27 22:24:09
【问题描述】:

在 ASP.NET Core 1.1 上,我尝试使用 BundlerMinifier 捆绑和缩小 CSS 和 JS,因此我在 .csproj 上添加了以下任务(我不再使用 project.json):

<Target Name="BeforePublish">   
  <Exec Command="bower install" />
  <Exec Command="dotnet bundle" />
</Target>

当我输入 dotnet run 时,项目运行,但即使我在 csproj 上有这些任务,也不会创建捆绑包。

注意:我在命令行上输入了dotnet bundle并创建了包,所以这不是问题...

这是完整的 csproj 文件:

<Project ToolsVersion="15.0">
  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" />

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp1.1</TargetFramework>
    <PreserveCompilationContext>true</PreserveCompilationContext>
  </PropertyGroup>

  <PropertyGroup>
    <PackageTargetFallback>$(PackageTargetFallback);portable-net45+win8+wp8+wpa81;</PackageTargetFallback>
  </PropertyGroup>

  <ItemGroup>
    <Compile Include="**\*.cs" />
    <EmbeddedResource Include="**\*.resx" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="System.Runtime" Version="4.3.0" />
    <PackageReference Include="Microsoft.NETCore.App" Version="1.1.0" />
    <PackageReference Include="Microsoft.NET.Sdk.Web" Version="1.0.0-alpha-20161104-2-112">
      <PrivateAssets>All</PrivateAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.0" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Design" Version="1.1.0-preview4-final " />
    <PackageReference Include="Microsoft.AspNetCore.Razor.Tools" Version="1.1.0-preview4-final" />  
    <PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration" Version="1.1.0" />
    <PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="1.1.0" />
    <PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.1.0" />
    <PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="1.1.0" />
    <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="1.1.0" />
    <PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="1.1.0" />
    <PackageReference Include="Newtonsoft.Json" Version="9.0.2-beta1" />
  </ItemGroup>

  <ItemGroup>
    <DotNetCliToolReference Include="BundlerMinifier.Core" Version="2.2.306" />
    <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.1.0-preview4-final" />
    <DotNetCliToolReference Include="Microsoft.Extensions.SecretManager.Tools" Version="1.1.0-preview4-final" />        
  </ItemGroup>

  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

  <Target Name="BeforePublish">   
    <Exec Command="bower install" />
    <Exec Command="dotnet bundle" />
  </Target>

</Project>

我错过了什么?

【问题讨论】:

  • 你有没有想过这个问题?我有同样的问题。

标签: asp.net-core


【解决方案1】:

这些是我的设置

操作系统:Windows 10。

IDE:Visual Studio 代码。

.NET Core 版本:1.1.

恐怕您还没有安装 BuildBundlerMinifier 软件包。因此,为了能够在运行 dotnet build 命令后运行捆绑,您必须按照以下步骤操作:

  1. 运行dotnet add package BuildBundlerMinifier,安装缺失的包。
  2. 运行 dotnet restore,恢复项目包。
  3. 现在,如果您运行 dotnet build,您应该会看到如下内容: bundling after building

你可以在https://github.com/pmargom/CarRentalMVC1.1看到整个项目。

希望对你有帮助!!

【讨论】:

    猜你喜欢
    • 2019-09-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-18
    • 2021-02-07
    • 2021-09-10
    • 2022-06-22
    相关资源
    最近更新 更多