I have a VCXProj file for a Universal Windows app that compiles some xaml files
<Page Include="..\View\ViewModel.xaml" />
One result of this is the xaml file is deployed as part of the package as a resource: ms-appx:///AppNamespace/ViewModel.xaml
If the file path was instead "View\ViewModel.xaml" then the resource path would also be "AppNamespace/View/ViewModel.xaml"
Unfortunately, since it is in the parent directory, it gets flattened and goes in the root. I want a way to specify the output path, rather than let the MSBuild system preserve it, something like
<Page Include="..\View\ViewModel.xaml">
<TargetPath>View\MyViewModel.xaml</TargetPath>
</Page>
But I cannot for the life of me find a way to do this. Is there anything out there?
I think this is by design, I couldn't find an option in VS tool that can specify the output path of a xaml file.
By default if you create a View folder in your project from VS, and create a new Page in this View folder, the VS compiler will automatically extract this XAML file out of the View folder and put it in the root folder of your project folder. And even you created one folder in the project from VS, this folder will not be created actually in your project physical folder.
For example, I created a folder named "Test" from VS, and I copied an image into this folder. The path of this image is actually like this:<Image Include="C:\Users\(pc-account)\Pictures\1.jpeg" />, and you will not find the "Test" folder in the physical path of this project. Now if we create a folder also named "Test" in the physical path, not only from VS, and copy another image into this folder, open this project from you VS, right click the "Test" folder, by adding existing item to select the second image into this "Test" folder, then you can see from VS:
And in the Appx folder of your project it looks like this:
As you can see, the first image which is added to the project from VS is extracted from the Test folder to the root folder, and the second image which is manfully added to the project is still in the Test folder.
You can see the path of this two images in the VCXProj file like this:
I'm afraid there is no options in VS tool that can automatically do this work, we can only
manually create a folder with the same name as one created from VS tool.
copy the .xaml, .xaml.cpp, and .xaml.h file into this manually-created folder.
add existing item from vs to this folder.
debug your project then you can see this View2 folder in the Debug folder.
in the meanwhile, in your VCXProj file you can see this xaml page's path:
Related
So I'm trying to set a custom image for a form application I've made. The images I'm trying to target are in a folder called "Images" on the same level as my Solution file. The solution file is a C# windows forms (net core framework) solution. It's a basic form app that I want to display an image based on a users selection, however right now I get an unhandled exception everytime I try to set the image with this code:
picFood.Image = Image.FromFile("../../Images/burger.jpg");
The exact error is "System.IO.FileNotFoundException: ../../Images/burger.jpg"
In another totally unrelated solution this works. Folder structure is the same. A folder called Images, on the same directory level as the .sln file holds the images there. They're in my solution explorer and everything. I've tried this with one "../" and no "../" as well so I'm not sure what to do from here.
Files with relative paths are opened relative to the working directory of your application.
In this case, when launching from within Visual Studio, the default is the bin folder where the compiled application is put by default.
So if your binary is in <project dir>/bin/Debug/App.exe this path will resolve to <project dir>/Image/burger.jpg.
If you have changed something in your build configuration, or your application switches directory at runtime (e.g. via Directory.SetCurrentDirectory), this path may be different than you expect.
To understand your issue, I suggest you start looking at what your working directory is. You can obtain that in your code via Directory.GetCurrentDirectory().
You can also resolve your relative path using Path.GetFullPath.
Print these two values to see where your program attempts to load the file from.
Keep in mind that any image files you put in the solution/project folder will need to be copied with your binary if you want to use them.
To use relative paths without .. you can copy them alongside your binary during compilation, see:
VS2010 How to include files in project, to copy them to build output directory automatically during build or publish and Copying Visual Studio project file(s) to output directory during build for how to do that.
When I build a windows application. It does not work because it cannot read my app.config file. I looked in the bin directory and it does not have the appname.exe.config file. If I manually copy over the app.config and rename it the appname.exe.config the application will work..but when I build the project this file is never created automagically. What am I missing? Why is my project not creating it? I have looked through the whole folder structure and there is no other config files.
Everyone here is giving you false information I think. I think #bowlturner had it right. According to Microsoft, you do need to set the app.config's Copy to output directory property to either Copy Always or Copy if newer. From Microsoft's MSDN Site:
When you develop in Visual Studio, place the source configuration file for your app in the project directory and set its Copy To Output Directory property to Copy always or Copy if newer. The name of the configuration file is the name of the app with a .config extension. For example, an app called myApp.exe should have a source configuration file called myApp.exe.config.
Visual Studio automatically copies the source configuration file to the directory where the compiled assembly is placed to create the output configuration file, which is deployed with the app.
The correct settings are:
Build Action = None
Copy to Output Directory = Do not copy
and very important, the project file needs to contain this element:
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
The only thing that worked for me was to delete bin\ and obj\ entirely. Rebuild and the file is created fine.
Look on App.config properties, should be:
BuildAction: None
CopyToOutputDirectory: Do not copy
Custom tool and custom tool namespace should be empty
Also try to Rebuild project. Right click on project -> Rebuild
Assuming you're using Visual Studio click your config file in the Solution Explorer and and in the Properties panel set Copy To Output Directory to something other than Do Not Copy.
I'd like to add files to a web csproj that are located under its directory, but in a different directory structure than the physical one. Example physical directory structure:
MyProject.csproj
Assets
Settings.config
Now my project needs the following structure when I publish the project (i.e. on the server when deployed) and would be nice if this structure would be visible from Visual Studio too:
MyProject.csproj
Config
Settings.config
Notice that Settings.config isn't in the Assets but in the Config folder.
I don't want to copy the files over, I can't move them and I can't change where these files are loaded from.
Is it possible for such files to be located in the Assets folder while
from VS they appear to be in the Config folder,
and when the project is published they are copied to the Config folder.
The latter one is possible with post-build tasks I think and I believe I can implement it. However I'd like to have the whole development experience, including the folder structure in VS, to show the file being under Config. Is this possible?
I'm looking for something like solution folders, but for projects. Adding files as links would work great, but since the files are in the physical folder of the project I get the error "Cannot add a link to a file that is inside the project tree".
I've 2 folders visible in Solution Explorer in my project (sample grid app):
fasdalocation and fasadalocation2.
fasadalocation was previously oryginal DataModel folder in sample grid app, fasadalocation2 is folder created by me.
Two folders contain identical file: SampleData.json.
I can acces to json file from fasadalocation by
Uri("ms-appx:///fasadalocation/SampleData.json")
unfortunatelly this don't work for fasadalocation2 (I got FileNotFoundException).
It's caused by fact that
C:\Users\Jakub\Documents\Visual Studio 2013\Projects\sample grid app\sample grid app\bin\Debug\AppX
location doesn't contain fasadalocation2.
How can I add fasadalocation2 into appx?
Of course I thought that simple insertion folder into AppX location isn't a gentle solution...
It looks like the 2 files are content files that need to be deployed to your output folder and one of them does not have the correct build action to copy it to the folder.
Right click on SampleData.json in the fasadalocation2 folder and ensure it's build action is set to Content and CopyAlways.
I've added an executable to my Visual Studio 2010 C# Solution. In the properties of this executable, the executable path is a full path ("C:\Test\MyProgram\MyProgram.exe")
When I deploy my solution (with installshield) on a new PC, the executable is part of the deployed solution together with some source files and the solution file. So far so good.
But when I open the installed solution file (in Visual Studio 2010),
I'm not able to build it because It can't find the executable in the specified path:
("C:\Test\MyProgram\").
Here is the question: How can change the full path of the executable, so it gets the path of where the solution is installed on the new PC. Something like :
"[InstallDir]\MyProgram.exe"
Thanks
Update: I found out that you can use relative path in Application's Executable path. Thanks for all your answers.
You could use TargetDir property
I am just thinking off the top of my head here. There may be a much simpler way. I'm thinking you might want to create a Custom Action that runs at the end of your installer that manually opens the .xxproj file, and manually edits the path of the reference. As another poster stated, you can get the new path from the TargetDir property: http://msdn.microsoft.com/en-us/library/aa372064%28VS.85%29.aspx
Example of creating Custom Actions: http://msdn.microsoft.com/en-us/library/9cdb5eda(v=vs.80).aspx
Add your Executable to your Project TO The Main Dir, right click-> Copy To OutPutDirectory -> Copy
this is easiest way to make your file to copy to your target dir, and have your SourceControl Visual studio plugin manage it.
Your executable should be be somewhere in your project source files structure, perhaps in a subfolder. When you add this executable file to project it should then be added on a relative path which is what you want. If this is not happening you should manually edit csprj file. To do this, right click on project, unload it, right click again and edit project file.
Of course, your executable file should have its property Build Action set to None and Copy to output Directory to what you want.
If for some reason you cannot add this executable directly into your project files structure I'd suggest to use pre-build event to copy it from where it exists into your project files.