Windows: How to compile WPF XAML-based program from command line? - visual-studio-express

I'm not very impressed with Visual Studio Express 2013, which is the free version of Visual Studio. I would greatly prefer to just compile my C# program form the command line. I've located the compiler csc.exe and I located the DLL files for .NET, but how can I compile a XAML file?

You want to use MSBuild (MSDN). This is the standard way to compile .NET projects from command line. This is also the compiler that Visual Studio uses internally. You have to have a .csproj/.sln file for it to work, but it will be the fastest and most effective way to get to where it sounds like you want to be.

You're looking for MSBuild. Visual Studio projects are XML scripts for MSBuild. To build a project or solution, you can use the following commands:
MSBuild MyApp.sln
MSBuild MyApp.csproj
Building XAML files is far from trivial and C# compiler isn't enough for this. The most recent MSBuild targets for XAML is in the C:\WINDOWS\Microsoft.NET\Framework64\v4.0.30319\Microsoft.Xaml.targets file. But doing all this manually isn't the best idea, you'll just overcomplicate things even if you manage to do everything without MSBuild.

Related

adding configuration to a solution after creating it so that it builds via MSbuild

I created a solution based of the different csproj files using solution maker tool. This tool creates a master solution but does not add configurations to the projects or the solution, the way Visual Studio adds configuration settings to the solution file when it builds it. I tried to build it using MSbuild new.sln command from the Developer Command prompt for VS2013. I even tried using the command by giving configuration options but it still doesn't work. The solution builds without actually building any output when triggered by MSbuild unless built in Visual Studio first. Is there a way for MSbuild or another way to add the configuration settings to the solution file so it can actually build it?
I used devenv to build the solution instead and it worked.

Compiling sqlite-winrt for using SQL in WinRT/WP app with SQLite

I'm trying to use the sqlite-winrt library at https://sqlwinrt.codeplex.com (cf. http://blogs.windows.com/windows_phone/b/wpdev/archive/2013/05/30/sqlite-winrt-wrapper-for-windows-phone.aspx) because I need to access an SQLite database via SQL commands in a WinRT 8.1 and a WP8 app and this library seems the only available option.
Anyway, there is no binary release and if I try compiling the source I get several link errors for unresolved externals against the SQLite DLL. I posted an issue at codeplex but got no reply yet, so I was wondering if anyone had already managed to successfully compile this lib and how (or if you know of any viable alternative for RT8.1 and WP8). Here is what I did:
downloaded the latest source from the site.
downloaded and installed 2 VSIX from http://www.sqlite.org/download.html: sqlite-winrt81-3080002.vsix for RT 8.1 and sqlite-wp80-winrt-3080100.vsix for WP.
executed the powershell scripts in each subfolder of the source code solution, which are required to update the projects with newer releases of the SQLite for WinRT extension. The current versions of the scripts refer to SQLite for WinRT 8.1 (prerelease) which is the same I downloaded above.
opened the VS2013 solution and removed the RT project (I just need RT8.1 and WP, this was for WinRT 8.0).
5) built the solution, which failed with link errors.
If I see the RT8.1 project properties, I can confirm the reference to SQLite is under C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1\ExtensionSDKs\SQLite.WinRT81\3.8.0.2.
Did anyone manage to use this lib? Thanks!
I also once had that problem. I fix it by editing the project file manually. At that time, the powershell script updating the wrong path. That's why I always failed when compiling my project. After I edit the project file using external text editor (I use sublime text), the projects are linked correctly.
You can try DatabasesCx. It is another SQLite Wrapper using Windows Runtime Component technology. It is freeware distributed as precompiled binary. You can find the details at http://www.almanacsoft.com/databasescx

How to bundle jre with .exe file created from .jar

I created .exe file from .jar file .Now my client demands to run the application without installing jre in the sytem.I have heard that with bundled jre it is possible ...but i dont know how to bundle jre with .exe file..
The JavaFX is working on this. Here are the up-coming features in Java SE 7 u10:
https://blogs.oracle.com/talkingjavadeployment/entry/packaging_improvements_in_jdk_7#3
https://blogs.oracle.com/talkingjavadeployment/entry/packaging_improvements_in_jdk_7
I have used VMware ThinApp to do exactly what you are trying to do. It does cost money, but works extremely well. It allows you to roll up all the dependencies your application uses into a single executable that can then run on vanilla installations of Windows. It can be used for a lot more than just Java, and it does so by recording the changes you make to a system after installing your application + the JRE for example, and then wraps up all of those changes. It certainly simplifies application deployment, since the applications are now portable. I've even used it to roll up Visual C++ redistributables, and .NET as well. This certainly increases the size of the executable, but it's also convenient knowing the application will run successfully. See more info at http://www.vmware.com/products/thinapp/overview.html.
The open source Launch4j allows you to produce an exe with an embedded JRE. This SO article also discusses this topic. Caveat: I've had very good success with Launch4j, but never used the embedded JRE feature.

how does msbuild decide which tools to use?

I'm trying to setup a new TeamCity agent.
My new agent is calling:
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\x86_amd64\CL.exe
While the existing agents are calling:
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\AMD64\CL.exe
The existing agents are doing the right thing as far as I'm concerned, because both are 64bit host and building 64bit binaries. Both are calling msbuild with the same arguments (specifics removed to protect the innocent):
C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe (xxxx.sln /clp:PerformanceSummary /p:Configuration=Release /p:Platform=x64)
I've found this blog: http://blogs.msdn.com/b/aaronhallberg/archive/2007/07/16/msbuild-property-evaluation.aspx, which explains how msbuild evaluate properties. But I don't know what properties are used to decide about the tools.
You might wonder why I care about the tool choice. The CL calls succeed in either case (you can run the 32 bit compile under 64bit windows). But on the new agent, I'm getting an error on a pre-compiled header "precompiled header file is from a previous version of the compiler, or the precompiled header is C++ and you are using it from C (or vice versa)" - and the pre-compiled header is being consumed by the same AMD64\CL.exe.
So if anyone knows which props msbuild actually uses, it would help me figure this out.
As a side note, I see the cross compiler (x86_amd64\CL.exe) in Visual Studio projects property pages under VC++ Directories, Executable Directories, on my workstation. Which is Win 7, 64bit. It says it is inherited, and I haven't customized the msbuild props (in C:\Users\bdelavega\AppData\Local\Microsoft\MSBuild\v4.0). Why would that be the default?
This post explains that msbuild defaults to using the cross compiler when called from VS 2010 and that there is a command line switch to override it.
http://social.msdn.microsoft.com/Forums/en-US/vcprerelease/thread/d6b352ea-12b6-4867-b86d-a052fbab1da4
It's not the complete answer, but it gives me enough to overcome my issue.

error in CUDA compilation

I'm getting this error while trying to run sample codes in CUDA SDK. I have CUDA 2.3 and Visual studio 2008
LINK : fatal error LNK1181: cannot open input file 'cutil32D.lib'
Any pointers how to solve this?
Since you're compiling the SDK samples, the project files are probably correct. Far more likely is that you haven't built the cutil library. Go to the SDK install directory, then into the "C" directory. You'll see a "common" directory, in there open the cutil.sln solution (or cutil_vc90.sln for VS2008) and build it in release and debug modes for your platform.
Then try your sample again.
The cutil library is used to avoid replicating the same code through all the samples, if you're starting your own project I'd avoid reusing the cutil library and write your own checker. For example, you should probably fail gracefully if you detect a CUDA error rather than just calling exit() as done in cutil.
The cuda.rules file included in the SDK is highly recommended! Using this you can just add .cu files to any project and Visual Studio will know how to compile them and link them in to the final executable. Easy!
Your MSVC project needs to include the library cutil32D.lib to link. Once you specify it as a library the linker needs to include in the final binary artifact this problem will go away. It would seem the library is missing at the location the linker is going to look for it. You'll have to change the library search paths or move that file to a directory in which the linker is already looking.
I ran into the same issue. It turned out not only did I need to build the cutil project but also the shrUtils project under the SDK's shared folder.