VS2010 How to include files in project, to copy th

2019-01-04 02:23发布

Task is to form Visual Studio 2010 project so, that during any build or publish some foo.exe utility should be copied to output (bin) directory.

Early I have made PostBuildEvent task in .csproj (MSBuild-file):

<PropertyGroup>
  <PostBuildEvent>
    Copy "$(SolutionDir)Tools\foo.exe" "$(ProjectDir)$(OutDir)foo.exe"
  </PostBuildEvent>
</PropertyGroup>

But this is not universal. During publishing (Visual Studio 2010) foo.exe appears in bin directory, but is not copied to output publish directory. Maybe I do everything completely wrong and there is standard mechanism to include files in projects to be later, during build or publish, copied to bin?

7条回答
Rolldiameter
2楼-- · 2019-01-04 03:04

There is and it is not dependent on post build events.

Add the file to your project, then in the file properties select under "Copy to Output Directory" either "Copy Always" or "Copy if Newer".

See MSDN.

查看更多
萌系小妹纸
3楼-- · 2019-01-04 03:04

In Solution Explorer, please select files you want to copied to output directory and assign two properties: - Build action = Content - Copy to Output Directory = Copy Always

This will do the trick.

查看更多
Melony?
4楼-- · 2019-01-04 03:08

Try adding a reference to the missing dll's from your service/web project directly. Adding the references to a different project didn't work for me.

I only had to do this when publishing my web app because it wasn't copying all the required dll's.

查看更多
爱情/是我丢掉的垃圾
5楼-- · 2019-01-04 03:10

I only have the need to push files during a build, so I just added a Post-build Event Command Line entry like this:

Copy /Y "$(SolutionDir)Third Party\SomeLibrary\*" "$(TargetDir)"

You can set this by right-clicking your Project in the Solution Explorer, then Properties > Build Events

查看更多
一纸荒年 Trace。
6楼-- · 2019-01-04 03:15

In my case, setting Copy to Output Directory to Copy Always and Build did not do the trick, while Rebuild did.

Hope this helps someone!

查看更多
唯我独甜
7楼-- · 2019-01-04 03:25
  1. Add the file to your project.
  2. Go to the Properties of that file.
  3. Set "Build Action" to Embedded Resource.
  4. Set "Copy to Output Directory" to Copy Always.
查看更多
登录 后发表回答