我有一个包含3个项目的解决方案。我需要将视图从一个项目复制到另一个项目。我可以通过post build事件复制创建的DLL,如:
所以我想将项目一中的文件'/Views/ModuleHome/Index.cshtml'复制到项目2中的文件夹中。 如何通过构建后事件将文件复制到我想要的项目?感谢
答案 0 :(得分:284)
xcopy "$(ProjectDir)Views\Home\Index.cshtml" "$(SolutionDir)MEFMVCPOC\Views\Home"
如果你想复制整个文件夹:
xcopy /E /Y "$(ProjectDir)Views" "$(SolutionDir)MEFMVCPOC\Views"
更新:这是工作版
xcopy "$(ProjectDir)Views\ModuleAHome\Index.cshtml" "$(SolutionDir)MEFMVCPOC\Views\ModuleAHome\" /Y /I
以下是一些常用的xcopy
开关:
/I - treat as a directory if copying multiple files
/Q - Do not display the files being copied.
/S - Copy subdirectories unless empty.
/E - Copy empty subdirectories.
/Y - Do not prompt for overwrite of existing files.
/R - Overwrite read only files.
答案 1 :(得分:20)
xcopy "your-source-path" "your-destination-path" /D /y /s /r /exclude:path-to-txt- file\ExcludedFilesList.txt
注意源路径和目标路径中的引号,但不是exludelist txt文件的路径。
ExcludedFilesList.txt的内容如下:.cs \
我正在使用此命令将文件从我的解决方案中的一个项目复制到另一个项目,并排除.cs文件。
/D Copy only files that are modified in sourcepath
/y Suppresses prompting to confirm you want to overwrite an existing destination file.
/s Copies directories and subdirectories except empty ones.
/r Overwrites read-only files.
答案 2 :(得分:13)
xcopy“$(TargetDir)* $(TargetExt)”“$(SolutionDir)\ Scripts \ MigrationScripts \ Library \”/ F / R / Y / I
/ F - 显示完整来源&目标文件名
/ R - 这将覆盖只读文件
/ Y - 禁止提示覆盖现有文件
/ I - 假设目的地是目录(但必须以...结尾)
一个小技巧 - 在目标中你必须以字符\结尾告诉xcopy目标是目录而不是文件!
答案 3 :(得分:7)
调用Batch
文件,该文件将Xcopy
运行所需的文件来源到目的地
call "$(SolutionDir)scripts\copyifnewer.bat"
答案 4 :(得分:7)
我这样使用它。
xcopy "$(TargetDir)$(TargetName).dll" "$(SolutionDir)Lib\TIRM\x86\" /F /Y
xcopy "$(TargetDir)$(TargetName).lib" "$(SolutionDir)Lib\TIRM\x86\" /F /Y
/F : Copy source is File
/Y : Overwrite and don't ask me
注意使用此。 $(TargetDir)已经'\' “D:\ MyProject \ bin \”= $(TargetDir)
您可以在命令编辑器中找到宏
答案 5 :(得分:2)
与之前的回复一样,我也建议xcopy
。但是,我想用/exclude
参数添加Hallgeir Engen的答案。该参数似乎存在一个错误,阻止它使用长或包含空格的路径名,因为引号不起作用。路径名称必须位于" DOS" -format中," Documents"转换为" DOCUME~1" (根据this source)。
因此,如果您想使用\ exclude参数,则需要解决方法here:
cd $(SolutionDir)
xcopy "source-relative-to-path-above" "destination-relative-to-path-above
/exclude:exclude-file-relative-path
请注意,源路径和目标路径可以(并且应该,如果它们包含空格)在引号内,但不是排除文件的路径。
答案 6 :(得分:2)
如果你想考虑平台(x64,x86等)和配置(调试或发布),它将是这样的:
xcopy "$(SolutionDir)\$(Platform)\$(Configuration)\$(TargetName).dll" "$(SolutionDir)TestDirectory\bin\$(Platform)\$(Configuration)\" /F /Y
答案 7 :(得分:0)
此命令对我来说就像一个魅力:
for /r "$(SolutionDir)libraries" %%f in (*.dll, *.exe) do @xcopy "%%f" "$(TargetDir)"
它递归将每个dll
和exe
文件从MySolutionPath\libraries
复制到bin\debug
或bin\release
。
您可以在here
中找到更多信息。