Visual C++ for Linux: copy content files to build directory? - linux

I have a Visual C++ for Linux project in VS2017 that I'm building on a Raspberry Pi running Raspbian. This project consists of a single source file (main.c) and an image (test.jpg). When building the project, I want the image file to also be deployed to the pi, so that the code in main.c can do something with it locally. However, I can't figure out how to do this
The image file's Content property is set to True, as is Included in Project. In the project properties, under Copy Sources, Sources to Copy is set to "#(SourcesToCopyRemotely)" and Copy Sources is set to "Yes". However, when I build, only main.c is copied to the Pi, and the compiler output is just a single .out file. I hoped to also see test.jpg there, but alas.
This article mentions that #(SourcesToCopyRemotely) defaults to all files in the project. However, when I evaluate the value of #(SourcesToCopyRemotely, it evaluates to just "main.c".
How do I make sure content files in my projects also end up in the build directory, along with the .out file? Preferably without having to manually enter each filename in a post-build step.

It turns out this is a bug in VC++ for Linux. A workaround, currently, is to use Additional Sources to copy. There's a caveat though: it doesn't work with remote paths that start with ~. So you can't use $(RemoteRootDir) if the Remote Build Root Directory setting is set to the default of "~/projects".
I've currently got Remote Build Root Directory set to "/home/pi/projects" and for each file I want to copy to the build directory I set Additional Sources to Copy to "[filename]:=$(RemoteRootDir)/$(ProjectName)/bin/$(Platform)/$Configuration)/[filename]". For instance:
firstimage.png:=$(RemoteRootDir)/$(ProjectName)/bin/$(Platform)/$(Configuration)/firstimage.png;secondimage.png:=$(RemoteRootDir)/$(ProjectName)/bin/$(Platform)/$(Configuration)/secondimage.png

Right-clicking on the non-source code file to open it's properties page and flagging as Content in the General tab will cause the file to be copied to the remote. There is no need to add anything to the Copy Sources tab. The Copy Sources page of the project properties must show the default of #(SourcesToCopyRemotely). And when you edit this setting the macro should show an expansion with the additional files included.
I have found that it necessary to refresh the macro by clearing Source to Copy and then restoring it to the default after you have marked the additional files as content.
I have encountered problems when the additional files are not in the same folder as the C++ source files on the Windows host and/or you want to put them somewhere else on the remote. There are several open issues on the VCLinux GitHub site like this one so it will be worth reporting any problems you have on there.
[VCLinux 1.0.6 on VS Pro 2017 + Debian Jessie remote]

The "Pre-Build Event" section of the project properties offers "Additional Files To Copy". Addressing my file there (relative to the solution) showed following in the output when building:
Copying file 'C:\myfilepath\resource.png' to '/home/pi/projects/myproject/resource.png'
It is possible to move the files to the final destination then with Remote Post-Build Events (mv source destination). Not the most elegant way, but the first thing I got working..

Related

Visual C++ for Linux Development "Debugging->Program" and "Copy Sources->Additional sources to copy" improvements

I am using VC++4LD and I have set everything to work, it works perfectly, I like the extension, but I have 2 places in the project settings that can be improved.
1st place is Debugging->Program, I have something like "$(RemoteProjectDir)/subfolder/another_subfolder/gcc.cmake/OUTPUTNAME" there and it works, but I want it to be in a more correct way. By default, there was "$(RemoteBuildOutputs)" and that was incorrect. I can't even figure out, what is stored in that string => I tried to echo it in Pre-Launch Command with both "echo $(RemoteBuildOutputs)" and "$(RemoteBuildOutputs)", but nothing was shown. The project is built with a script that jumps into the "/subfolder/another_subfolder/" first.
So how to find, what is stored in $(RemoteBuildOutputs) and how to set the Debugging->Program dynamically so I can reuse it in other projects?
2nd place is Sources->Additional sources to copy, there is a lot of "CMakeLists.txt" files in the project and all are added to the project via "Include In Project", but they aren't copied to the remote machine during the build, I fixed it by specifying all the separate "CMakeLists.txt" files in "Copy Sources->Additional sources to copy", but it was a hard work to list them all.
How to automatically copy all CMakeLists.txt to the remote machine without specifying them separately so I can again reuse it in other projects containing any CMakeLists.txt?
EDIT: 1 more thing => I include linux project into VS with "Show All Files", then I select all folders and remaining files outside of them and choose "Include In Project" from the context menu, but all CMakeLists.txt remain unincluded in project, how to solve it, so I don't have to go through all of them and include them 1 by 1?
$(RemoteProjectDir) etc. are Visual Studio build macros that are expanded from pre-defined information like the project name and information entered into the project properties. They're not stored in environment variables. I don't know if there's a simple way to print the value of a macro but you can get VS to list the substitutions it makes by turning up the MSBuild verbosity : goto Tools/Options , Projects and Solutions / Build and Run page and set the MSBuild project build logfile verbosity to diagnostic (you probably want to use the log file 'cos it can spit out a lot of stuff).
As for CMake, various issues around it have been raised on the VClinux GitHub site . That would be the place to ask for enhancements. You might also look at VCLinux unoffical scripts to see whether any of Marc's scripts can help you automate the project creation.
You can open the Dropdown menu on that setting and click on <Edit>:
In the opening Window you'll see the expanded Macros:
In case anyone stumbles onto this because of the Edited supplemental question, I had the same problem in visual studio not adding every file after "Show all files" and hitting "Include in Project." Certain files like "makefile.am" and configure scripts were not getting included and therefore, were not getting copied over to the Linux system during build. My solution was to edit the .vcproj file and add a line that will include everything in a specified directory. This can be done for a specific folder or recursively.
For instance, if I wanted to add everything in folder "A" I would add,
<ItemGroup>
<None Include="A\*" />
</ItemGroup>
If I wanted to add everything in folder "A" and well as all sub-folders and sub-folder contents,
<ItemGroup>
<None Include="A\**" />
</ItemGroup>
Care should be taken not to double included items. Also, this should only apply to non-source items that will not be compiled. Otherwise the "None" indicator should be appropriately changed (CLInclude for headers, CLCompile for c/cpp, etc).

Corflags.exe cf001 Could not open file for wiriting

I am trying to edit the corflags file so that I can run 32bit applications on a 64 bit pc but everytime I try to edit the file using something like corflags.exe assembly /32bit+ it comes up with the error message cf001 could not open file for writing.
Now I have tried a lot of different options such as:
Running in administrator mode;
Finding the file using a search and checking read only is not ticked
Checking that user full control is ticked
Tried to set the whole folder to non read only
When trying the whole folder, it goes through looking like it has set read-only, but then I click OK and re-right click on the whole folder, the box is filled in (not ticked) does this mean that part of the folder is read only and why does it reset to read only?
I just faced the same problem and have tried the same things.
Run cornflags from an elevated ("Run as administrator") Visual Studio Command Prompt. I did the same for a copy of the original .exe just to make sure no other process was using the program.
Create a copy of the file you intend to target with CorFlags.
(e.g. "WcfServiceHost.exe" --creates--> "WcfServiceHost - Copy.exe")
Rename the original file to something else:
(e.g. "WcfServiceHost.exe" --> "WcfServiceHose_Original.exe")
Rename to copy to the original file name
(e.g. "WcfServiceHose - Copy.exe" --> "WcfServiceHost.exe"
For my purposes, I created copies and named them describing their configuration:
Example:
WCFServiceHost_With32BitOn.exe
WCFServiceHost_With32BitOff.exe
Now I can destroy the WCFServiceHost.exe files and create them from these pre-modified copies. No more CorFlags operations necessary.
Note: this is basically a more verbose version of #RMalke answer and that answer should be marked as the answer.
I realise this is years later, but for anyone else looking, I found that the quickest way was to copy cmd and corflags.exe into the same folder as the one you want to edit. Then run cmd as admin from there.

Error installing cab file on Windows CE

I'm having trouble using macros in my .inf file that I'm using to create my cab, specifically when setting the InstallDir string. If I do something like this:
InstallDir=\<PathToProgramFiles>\MyAppName
then everything works fine. However, if I do this:
InstallDir=%CE1%\MyAppName
then I get the following error when trying to install the cab (double tapping it on my device): "MyAppName was not installed successfully. Please run Setup again."
This only seems to apply to the built-in macro strings. I can use %AppName% without any problems. Maybe there is some registry setting that isn't properly set that would normally resolve the %CE1% macro?
Any ideas about what is going on?
Edit: My device doesn't have a \Program Files directory. It seems the %CE1% macro always resolves to that path and if the InstallDir specified in the inf file doesn't exist (with the exception of the last directory portion then the install fails. Manually creating \Program Files fixed the issue. Since a lot of the devices I'm working with have different paths for their Program Files directory, is there a generic way to get the installer to default to the actual Program Files dir? I guess my only other option is to not specify a path and force the user to choose one?
First, in this link you can find the shortcuts and their meaning (the %C..%), goto appendix B. The Windows CE5 MSDN link.
You can add a Setup Dll to your CAB installaer that will check the directory structure and will create a folder in case it does not exist. You may find this SO question useful.
A warning: If you are targeting regular Windows CE devices, beware where you place the files as it can be to a RAM based file system and then the files will disappear after reboot.

Installshield - How do I make installshield build the entire cd?

Right now the Release build just makes the files necessary for the install. But I want to create the CD structure automatically with InstallShield, so that when I go to Tools, Open Release Folder
it has
\Install
\Tools
\Help
autorun.inf
I've looked at the execute batch file or copy to folder options for a Release, I was hoping there was something more friendly within InstallShield.
using version 12.
I created a feature / component called CDOnly which is not visible, selected, and doesn't copy, but does put the files in the Disk Images / Disk1 folder.
So by changing the default directories of features and putting special things in CDOnly I was able to create the structure I wanted.

Is there a speedfolder like entity in installshield?

I seem to have received the privilege of picking up some install shield projects. I've used install anywhere in the past and I was wondering if there was an equivalent of speedfolder in installshield. A speedfolder is a way of blindly copying an entire folder into the project without explicitly selecting each file.
There are a couple of ways you can do this.
Dynamic File Linking or using the Files and Folders view.
With Dynamic File linking you can point your project to a directory or directories and IS will refresh the list of files at build time and add them to your install.
The files and folder view can be used to drag and drop a whole load of files and folders in to your project in one go.
If you choose to use Dynamic File Linking be sure to read up on the implications first. Check out the Installshield help file

Resources