我已将asp.net核心项目迁移到VS2017 RC,现在它支持从项目中排除文件的功能。我已经排除了两个文件夹,它们将这些行添加到我的csproj文件中:
<ItemGroup>
<Content Remove="wwwroot\dist\**" />
<Content Remove="wwwroot\lib\**" />
</ItemGroup>
这很有效,除非现在这些文件不再发布。如何从项目中排除这些文件夹,但仍将它们包含在发布中?
答案 0 :(得分:9)
从dotnet新spa模板中获取的以下msbuild项目帮助我实现了我相信你所追求的目标:
<ItemGroup>
<Content Remove="wwwroot\dist\**" />
<Content Remove="wwwroot\lib\**" />
</ItemGroup>
<Target Name="GiveAName" AfterTargets="ComputeFilesToPublish">
<!-- As part of publishing, ensure the JS resources are freshly built in production mode -->
<Exec Command="npm install" />
<Exec Command="npm etc etc do your stuff" />
<Exec Command="or webpack" />
<!-- Include the newly-built files in the publish output -->
<ItemGroup>
<DistFiles Include="wwwroot\dist\**; wwwroot\lib\**" />
<ResolvedFileToPublish Include="@(DistFiles->'%(FullPath)')" Exclude="@(ResolvedFileToPublish)">
<RelativePath>%(DistFiles.Identity)</RelativePath>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</ResolvedFileToPublish>
</ItemGroup>
</Target>
答案 1 :(得分:2)
我通过在csproj文件中的PrepublishScript
目标中添加以下行来解决这个问题,因为似乎没有一种优雅的方法来实现它。
<Target Name="PrepublishScript" BeforeTargets="PrepareForPublish" Condition=" '$(IsCrossTargetingBuild)' != 'true' ">
<!-- Other things here already -->
<ItemGroup>
<Lib Include="wwwroot/lib/**;" />
<Dist Include="wwwroot/dist/**;" />
</ItemGroup>
<Copy SourceFiles="@(Lib)" DestinationFolder="$(PublishDir)\wwwroot\lib\%(RecursiveDir)" SkipUnchangedFiles="true" />
<Copy SourceFiles="@(Dist)" DestinationFolder="$(PublishDir)\wwwroot\dist\%(RecursiveDir)" SkipUnchangedFiles="true" />
</Target>
答案 2 :(得分:0)
您可以使用Condition
满足您的需求,例如:
<ItemGroup Condition=" '$(Configuration)' == 'Debug' ">
<Content Remove="wwwroot\dist\**" />
<Content Remove="wwwroot\lib\**" />
</ItemGroup>
编辑:
或者尝试:
<ItemGroup>
<Content Condition=" '$(Configuration)' == 'Debug'" Remove="wwwroot\dist\**" />
<Content Condition=" '$(Configuration)' == 'Debug'" Remove="wwwroot\lib\**" />
</ItemGroup>
编辑2:
由于看起来IDE会尊重Condition
,您可以改为将项目从Content
更改为None
并添加BeforePublish
目标,以添加等效{ {1}}项目。
编辑3:
具体来说,请保留原文
Content
并在<ItemGroup>
<Content Remove="wwwroot\dist\**" />
<Content Remove="wwwroot\lib\**" />
</ItemGroup>
</Project>