How to pass a custom build property to csproj? - visual-studio-2012

How to pass custom build properties to csproj file ? My csproj is upgraded from VS2008 to VS2012.
Under MSBuild3, the build runs fine. I am able to access the custom properties. However, under on MSBuild4, I have the following warning.
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.CSharp.targets(316,9): warning MSB3052: The parameter to the compiler is invalid, '/define:MyCustomProp=WHATEVER' will be ignored. [C:\src\MyProj\MyProj.csproj]
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.CSharp.targets(316,9): warning MSB3052: The parameter to the compiler is invalid, '/define:MyCustomPropTwo=WHATEVERTWO' will be ignored. [C:\src\MyProj\MyProj.csproj]
I am running this build under MSBuild 4 using script written in VS2008.

To pass a custom property to the msbuild commandline use the /p:PropertyName=PropertyValue command switch, this can be used multiple times. The PropertyName is then available within your msbuild script as $(PropertyName). See msbuild commandline reference
CSharp.targets file is an msbuild file, so you will have to lookup, which properties you want to pass.

Related

Typescript giving "Output Generation Failed" in Visual Studio 2012 with 0.9.5

I've been using Typescript 0.9.5 for the last few days, and then suddenly today the JavaScript files just stopped being generated. I see an error "Output generation failed" in the Visual Studio status bar, but nothing in any of the output windows.
I've rebooted, and restarted Visual Studio, disabled Web Essentials, tried all the usual things.
The files are set as TypescriptCompile in the properties. I've tried adding new files, or editing old ones with no effect. The Project file hasn't been changed as far as I can tell (its in TFS and none of the TypeScript sections have been altered).
I've made sure both files are checked out, still nothing.
Update: I've managed to compile manually using tsc.exe from the command line, so it must be something in Visual Studio.
OK, so I solved the problem.
One of my files contained invalid typescript, specifically trying to export a class when not inside a module. This caused all typescript files to fail to generate, but with no useful error message.
The following file would cause the problem:
export class Test {
public DoSomething() {
}
}
Either removing the export keyword, or adding a wrapping module solved the problem.
I've raised it as an issue here: https://typescript.codeplex.com/workitem/2109
Update: More details.
The above syntax is valid if you are using the CommonJS or AMD module patterns.
To enable this in visual studio you need to edit the .csproj file and insert a new PropertyGroup:
<TypeScriptModuleKind>AMD</TypeScriptModuleKind>
If you have an export outside of an internal module Typescript tries to compile it as either commonjs or amd module format. The compilation will fail if the a --module flag is not present on the command line. Use your project properties to set it to the desired value (probably amd in your case).
More info on TypeScript modules : http://www.youtube.com/watch?v=KDrWLMUY0R0&hd=1

PostSharp warnings when using fakes in VS2012

We've updated to VS2012 recently and also changed our PostSharp version to 3.0.26. Generally this combination works fine, but I get warnings for my unit test project such as
The module "MyModule.Fakes.dll" does not contain any aspect or other transformation. For improved build-time performance, consider disabling PostSharp for this module by setting the compilation symbol (aka constant) "SkipPostSharp" in your project or set the MSBuild property "SkipPostSharp=True".
Now usually I can disable this warning by changing the project settings accordingly (SkipPostSharp = True), but I've already done that for my MyProjectTest project containing the unit tests.
When I add <SkipPostSharp>True</SkipPostSharp> to my MyModule.Fakes file in the Fakes folder, the warning about PostSharp disappears, however, I get another error message:
The element "Fakes" in namespace "http://schemas.microsoft.com/fakes/2011/" has invalid child element "SkipPostSharp" in namespace "http://schemas.microsoft.com/fakes/2011/". List of possible elements expected: "StubGeneration, ShimGeneration, Compilation" in namespace "http://schemas.microsoft.com/fakes/2011".
Update
I also tried editing the fakes.xsd file and add an extra SkipPostSharp element, but a) this still isn't recognised as a valid element by Visual Studio and b) I'm not sure whether this would be the right approach anyway.
Any ideas how to get rid of these warnings?
You can specify additional properties for the project file Fakes will generate to build the fakes assembly by placing Property elements inside of the Compilation element at the end of the .FAKES file. Here is an example based on your description.
<Fakes xmlns="http://schemas.microsoft.com/fakes/2011/">
<Assembly Name="MyModule"/>
<Compilation>
<Property Name="SkipPostSharp">True</Property>
</Compilation>
</Fakes>

Visual Studio 2012 undocumented warning C4447

dllmain.cpp(16): warning C4447: 'main' signature found without threading mode
l. Consider using 'int main(Platform::Array<Platform::String^>^ args)'.
Above is a warning I got from building a Windows Store App DLL project. I didn't change anything in that default dllmain.cpp file except for including my own version of pch.
The documentation for this warning (along with many VS2012 errors/warnings) is nowhere to be found on MSDN and here is the only relevant link I can find:
http://social.msdn.microsoft.com/Forums/en-US/vssetup/thread/6daa9587-fe54-4e84-a8b9-0e5c52c2f6e8/
and the op there didn't get an answer.
If anyone knows what it means and how to fix it, it would be great!
As far as I can tell, you can safely ignore the warning. The compiler cribs when it sees a Win32-style DllMain being compiled using the /ZW flag (Consume Windows Runtime Extensions). However, the function gets called as you'd normally expect.
Alternatively, you can work around the warning by compiling dllmain.cpp without /ZW. You might need to adjust the PCH settings for this to properly work. This is the path taken by the DLL (Windows Store apps) C++/CX project template in Visual Studio.
Incidentally, the reason you do not get the warning when you're trying to build a Windows Runtime Component project (which builds everything using /ZW) is that a Windows Runtime Component doesn't declare a DllMain. This is not to say that it can't; it just picks up the dummy DllMain that the CRT defines (which basically turns off per-thread initialization and reports success).

Cruise Control .NET ignoring project dependencies

I have been using CC.Net successfully for some time, but now I have a problem. I added new solution to CC. It is compiled fine in VS2008, but fails in CC. The main reason is - projects in solution are built in wrong order, with no regard to dependencies. CC just tries to build them in the same order as they are stored on disc (alphabetical order).
For example, in solution there is proect Proj1 and Proj2, Proj1 has reference to Proj2. On CCNET Proj1 is built before Proj2 and throws error "CSC : error CS0006: Metadata file 'D:\xxx\Proj2\bin\Debug\Proj2.dll' could not be found".
I know this could happen when devenv is used to build solutions, but I use MSBuild.
The following code is responsible for building:
<exec>
<executable>C:\WINDOWS\Microsoft.NET\Framework\v3.5\MSBuild.exe</executable>
<baseDirectory>code\src</baseDirectory>
<buildArgs>/p:Configuration=Debug /t:Rebuild PM.sln</buildArgs>
<buildTimeoutSeconds>1200</buildTimeoutSeconds>
</exec>
What am I doing wrong?
The error Metadata file could not be found:
When it happened to me, it was because there was a file called proj1.exe at that location that should not have been there. So when it used proj1.exe as the reference (instead of a proj1.dll), proj1.exe's reference to a local System.EnterpriseServices.dll failed. This was happening to me with proj1.exe referencing System.EnterpriseServices.dll which referenced System.EnterpriseServices.Wrapper.dll. Where proj1.exe was not supposed to be included in the build but someone had named a unit test app project against our team conventions.
So I recommend checking the references in the project files(unload project and edit project in vs2010 or open each project file with a text or xml editor) to make sure they are ProjectReference not Reference. Also try doing the build with /v:d in the buildArgs list so you get a more detailed build log that will show you where files were resolved to and in what order. Aa different reference that is 'successfully' resolved could be attempting to load x.dll that directly locally references your D:\xxx\Proj2\bin\Debug\Proj2.dll but fails.

How do I eliminate error C2859 when trying to use a precompiled header with VS2010 (VC100) in debug mode?

I am trying to upgrade an old solution to use VS2010 (VC100).
I have it setup so that stdafx.cpp will create a precompiled header stdafx.pch from stdafx.h. Then all the other .cpp files that include stdafx.h are instructed to use the precompiled header.
These posts helped me get this far:
Visual C++ Precompiled Headers errors
Precompiled Headers
Now all is fine when I build in release mode. However when I try and build in debug mode I get a whole heap of errors saying:
Error 1 error C2859: [removed]\debug\vc100.idb is not the idb file that was used when this precompiled header was created, recreate the precompiled header.
I believe that this .idb file is an intermediate debug file created by Visual Studio.
Why am I getting this error? In other words why did it not use this .idb file when it created the precompiled header?
I'm not sure what further information you need to be able to give me answer so just ask if there is more information that I need to provide.
Thanks to a colleague I got the answer.
The problem was that stdafx.cpp had Debug Information Format set to Program Database (/Zi) where as all the other files had it set to Program Database for Edit and Continue (/ZI).
Changing them all to Program Database for Edit and Continue (/ZI) and doing a full rebuild solved the problem.
I guess the upgrade screwed it up somehow.
I've hit this error with VS2005 when compiling a project where the $(ProjectName) is different from the actual output file of the project (i.e. Linker > Output File isn't set to the default of $(OutDir)\$(ProjectName).exe but to something else, e.g. $(OutDir)\$(ProjectName)-custom_postfix.exe)
In this case, and apparently only when doing a Rebuild-Project-Only, the vc80.pdb seems to be looked up wrongly.
What helped me was to additionally set C/C++ > Output Files > Progam Database File Name to $(IntDir)\$(TargetName).pdb. (Instead of the default vc80.pdb)
select Disable for the Debug Information Format in the Properties page for stdafx.cpp, then go back and select Inherit from parent worked for me.
Maybe your release build is configured to write file [removed]\debug\vc100.idb instead of [removed]\release\vc100.idb? Check the project settings for your release build and make sure there are no hardcoded path components like that.
Here's how I just fixed this error on Visual Studio 2008:
Background:
I have a solution that contains two sub-projects.
One project compiles the .dll;
One project compiles the .exe that used this .dll;
The .exe project is dependent on the .dll project;
Problem: I had both of the projects dumping their output into the same directory, i.e. both "OutPutDirectory" and "IntermediateDirectory" set to write to a common directory in the root, "../$(ConfigurationName)".
Cause of error:
The cause of this error was that when the .dll project was compiled, it created the precompiled header (*.pch) in the same directory as the .exe directory, and when the .exe project was compiled, it promptly overwrote the precompiled header (*.pch) from the .dll project.
The fix:
To fix this, I changed the "IntermediateDirectory" for both sub-projects to "temp", so that the temporary files (including the precompiled header files) were written to different directories.

Resources