2017-08-27 30 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