2017-08-27 106 views
0

我想添加和删除文件,当我的MSBuild 15的MSBuild:添加和删除文件到的MSBuild 15发布输出@ BeforeTargets =“PrepareForPublish”

<Project Sdk="Microsoft.NET.Sdk.Web"> 

    <PropertyGroup> 
    <TargetFramework>netcoreapp2.0</TargetFramework> 
    </PropertyGroup> 

    <ItemGroup> 
    <Folder Include="wwwroot\" /> 
    </ItemGroup> 

    <ItemGroup> 
    <PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" /> 
    </ItemGroup> 

    <!-- My target, which is only executed on publication , Which is desirable in my case --> 
    <Target Name="MyPrepareForPublish" BeforeTargets="PrepareForPublish"> 

    <!-- Delete old files in wwwroot from Content --> 
    <ItemGroup> 
     <Content Remove="wwwroot\**"/> 
    </ItemGroup> 

    <!-- I Add and removes files to file system in wwwroot here , Exclude="@(Content)" prevents duplicates from outside wwwroot --> 

    <!-- Adding new files to Content form wwwroot --> 
    <ItemGroup> 
     <Content Include="wwwroot\**" Exclude="@(Content)"/> 
    </ItemGroup> 

</Target> 

</Project> 

发布但当我删除和添加文件,我得到一个错误信息:

(109,5): Error MSB3030: Could not copy the file "C:\buildTest\WebsSrver\wwwroot\main.d158e9e1259986c4bd76.bundle.js" because it was not found. 

我的代码删除“main.d158e9e1259986c4bd76.bundle.js”,并创建一个新的与MyPrepareForPublish另一个名字。

这些文件位于wwwroot im my dotnet核心项目中。

那么如何指定发布输出中应包含哪些内容?

在此先感谢!

+0

该目标究竟是什么?你添加/删除“内容”项目?你使用的是2.0.0 SDK吗? (它有一些修复这种情况下) –

+0

你使用2.0.0:是的,我认为是这样的 “C:\ Program Files \ dotnet \ sdk \ 2.0.0 \ Sdks \ Microsoft.NET.Sdk \ build \ Microsoft .NET.Publish.targets“和在proj文件的topp中。该目标究竟是什么? :你的意思是什么? –

+0

我的意思是你的'MyPrepareForPublish'目标用来修改文件和项目 –

回答

1

在预发布目标期间添加文件时,SDK还会添加相应的ContentWithTargetPath项目。但是,由于发布目标仅使用ContentWithTargetPath,因此SDK不会跟踪对Content项的移除和修改,因此发布目标仅使用ContentWithTargetPath

您应该能够通过删除项目组中删除并重新添加Content项目,简单地删除遗留的定制步骤后ContentWithTargetPath来解决你的问题已经像这样运行:

<ItemGroup> 
    <ContentWithTargetPath Remove="@(ContentWithTargetPath)" Condition="!Exists('%(FullPath)')" /> 
</ItemGroup> 

2.0。 0 SDK将自动为新生成的文件添加ContentWithTargetPath