2013-08-07 49 views
4

我有兩個許可文件,我希望在我的\bin目錄中包含這兩個文件,這兩個文件在構建時都會發布。將文件添加到構建和發佈的bin目錄中

這兩個文件都在App_Data目錄(其初始位置並不重要,他們只需要在\bin落得),並具有以下屬性設置:

  • Build Action = Content
  • Copy to Output Directory = Copy Always

當我構建或發佈時,它們不在\bin中。

我的設置有什麼問題:設置,文件夾,文件,其他...?

UPDATE

我把文件從App_Data目錄,並把他們在項目的根,現在它們被複制到\bin上構建。

回答

7

我已經通過稍微擴展我的.csproject文件在幾個項目中完成了這項工作。下面的代碼應該放在WebProject.csproj的Project節點的正下方。 的AfterBuild目標簡單的拷貝一組文件(在這種情況下,「未引用的DLL」)從Visual Studio中建立正常時的bin文件夾。 CustomCollectFiles在部署時基本上做同樣的事情。

<PropertyGroup> 
    <UnreferencedDlls>..\lib\Unreferenced\**\*.dll</UnreferencedDlls> 
    </PropertyGroup> 
    <PropertyGroup> 
    <CopyAllFilesToSingleFolderForPackageDependsOn> 
     CustomCollectFiles; 
     $(CopyAllFilesToSingleFolderForPackageDependsOn); 
    </CopyAllFilesToSingleFolderForPackageDependsOn> 
    </PropertyGroup> 
    <Target Name="AfterBuild"> 
    <Message Text="Copying unreferenced DLLs to bin" Importance="High" /> 
    <CreateItem Include="$(UnreferencedDlls)"> 
     <Output TaskParameter="Include" ItemName="_UnReferencedDLLs" /> 
    </CreateItem> 
    <Copy SourceFiles="@(_UnReferencedDLLs)" DestinationFolder="bin\%(RecursiveDir)" SkipUnchangedFiles="true" /> 
    </Target> 
    <Target Name="CustomCollectFiles"> 
    <Message Text="Publishing unreferenced DLLs" Importance="High" /> 
    <ItemGroup> 
     <_CustomFiles Include="$(UnreferencedDlls)" /> 
     <FilesForPackagingFromProject Include="%(_CustomFiles.Identity)"> 
     <DestinationRelativePath>bin\%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath> 
     </FilesForPackagingFromProject> 
    </ItemGroup> 
    </Target> 

您需要修改的部分是基本UnreferencedDlls節點,以配合您的文件夾結構。 **\*.dll部分僅僅意味着「此處下面的任何級別的每個DLL文件」。

+0

聽起來可行 - 我會試試 – wilsjd

+0

我加了這個,但它似乎沒有做任何事情。 – wilsjd

+0

讀這個更接近一點,我認爲這隻會在我有「總是複製」選項時正常工作?似乎該選項會將其複製到文件夾內的bin文件夾,然後將這些文件直接放入bin文件夾中,是嗎? – wilsjd

0

不一定是直接的答案,但我強烈建議不使用在「發佈」機制出爐,而是線了一個構建腳本(可能在PowerShell中),會做你需要的一切。將MSBuild和nUnit掛鉤並複製文件並移動它們非常簡單。

POWERSHELL(粗糙)例子。

# Get Directory Location 
$invocation = (Get-Variable MyInvocation).Value 
$directorypath = Split-Path $invocation.MyCommand.Path 

# Build the application using MSBuild 
cmd /c C:\Windows\Microsoft.NET\Framework\$v4_net_version\msbuild.exe "$directorypath\MyProject.sln" /p:Configuration=Release 

# Run the tests using nUnit 
cmd /c $directorypath\build\nunit\nunit-console.exe $solutionPath\MyProject.Tests\bin\debug\MyProject.Tests.dll 

# Copy the license to the appropriate directory 
Copy-Item -LiteralPath "$directorypath\mylicensefile.txt" "$directorypath\bin\release" -Force 

# NOTE: You are going to have to adjust this to match your solution and projects. 
+0

我得到了你的說法,但我們已經有了一個漂亮的建立工作流程。我明白爲什麼我們應該考慮朝着這樣的方向前進。 – wilsjd

1

如果您使用的Visual Studio

  • 顯示您的文件屬性(您的文件或點擊右鍵單擊它然後選擇屬性
  • 複製到輸出目錄屬性選擇複製總是複製如果更新

在構建時,該文件會在bin目錄下複製:調試或發佈...

相關問題