Step by step:
1. open your solution
2. right click on solution explorer to add a setup project
3. right click on setup project new created to add a new project output, OK
4. right click on setup project and select property
5. Prerequisites, 系统必选, 将需要include的framework钩上.
6. 钩选第二项,从与我系统相同位置下载
7. rebuild, you can see the files below in debug folder:
DotNetFX40Client
dotNetFx40_Client_x86_x64.exe
WindowsInstaller3_1
WindowsInstaller-KB893803-v2-x86.exe .exe
setup.exe
setup1.msi
Link: