I'm pretty new to MSBuild, so I might be doing something obviously-wrong, but a colleague of mine who's worked with MSBuild a lot can't see any error, so I figured I'd post here and see if anyone else can see it.
I'm converting an old batch file that we used to call ant to MSBuild tasks (because we want to call it from MSBuild) and the environment variables always expand to )for reasons we don't understand.
I have a property group that includes
<PropertyGroup>
<EnvJavaHome>
$([System.Environment]::GetEnvironmentVariable("JAVA_HOME"))
</EnvJavaHome>
<!-- ... -->
</PropertyGroup>
(line breaks added for legibility). Now the MSBuild Property Functions reference suggests I'm calling System.Environment.GetEnvironmentVariable correctly, but I always get a value of ). The code works perfectly well when I hardcode the value, however.
What obvious thing am I missing? :o)
If it's an env variable, you should be able to just use it like $(JAVA_HOME)
as in <EnvJavaHome>$(JAVA_HOME)</EnvJavaHome> , see e.g. use http://msdn.microsoft.com/en-us/library/ms171459(v=VS.100).aspx
(Check that the environment variable actually exists though, echo %JAVA_HOME% in a command window)
Related
What do I miss in using CPackDeb? (cmake version 3.5.1)
For example, if I want to find out CPACK_DEBIAN_PACKAGE_ARCHITECTURE, an empty string is returned. If I clone the respective code, everything works as expected. Also, other
https://cmake.org/cmake/help/v3.0/module/CPackDeb.html specific variables seem to not work, and also my KDevelop does not highlight them.
Since using include(CPackDeb) results in error message CPackDeb.cmake may only be used by CPack internally, I presume there is some other way (a missed parameter?) to activate it.
After I have fixed this warning, how can I make it an error, so it doesn't slip in again?
msbuild /p:TreatWarningsAsErrors doesn't work
No happy answer to give you here. The TreatWarningsAsErrors property only affects the C# and VB.NET compiler (not C++), it determines the value of their /warnaserror command line option.
But MSB3277 is generated by an MSBuild task, ResolveAssemblyReference, its internal LogResult() method generates the diagnostic. The only property the class has that helps treat warnings as errors conditionally is WarnOrErrorOnTargetArchitectureMismatch, not what you are trying to achieve. You can have a look-see for yourself with a decompiler, look at C:\Program Files (x86)\MSBuild\12.0\Bin\Microsoft.Build.Tasks.v12.0.dll. The resource name for the localized MSB3277 message is "ResolveAssemblyReference.FoundConflicts".
So only way to get ahead here is to write a little utility that parses the log file and looks for the warning.
You can use the generic mechanism MSBuildTreatWarningsAsErrors or <MSBuildWarningsAsErrors>MSB3277</MSBuildWarningsAsErrors> (introduced in #1928) to accomplish this.
credit: rainersigwald
Run Update-Package via Package Manager Console, this will fix MSB3277, what it does it reinstall all the packages and all related assemblies they come with to the highest version possible.
More info on official docs https://learn.microsoft.com/en-us/nuget/consume-packages/reinstalling-and-updating-packages
It looks like the /warnaserror will promote all msbuild warnings to errors:
TreatWarningsAsErrors vs /warnaserror
I'm seeing a strange build bug a lot. Sometimes after typing some code we receive the following build error.
Class 'clsX' must implement 'Event PropertyChanged(sender As Object, e As PropertyChangedEventArgs)' for interface System.ComponentModel.INotifyPropertyChanged'.
And
'PropertyChanged' cannot implement 'PropertyChanged' because there is no matching event on interface 'System.ComponentModel.INotifyPropertyChanged'.
Those error should never go together! Usually we can just ignore the exception and build the solution but often enough this bug stops our build. (this happens a lot using Edit and Continue which is annoying)
We're using Vb.net and c# mixed in one big solution.
Removing the PropertyChanged event and retyping the same code! sometimes fixes this.
Question:
Has anyone else seen this problem and has some suggestions how to prevent his?
We're using a code generator that causes this error to surface but just editing some files manually triggers this exception too. This error occur's on multiple machines using various setups.
Someone had the same exact issue discussed here. It sounds like there is an issue with this build picking up an old version of a binary. I would try the following in order:
Verify all assembly references use project references where possible within the Visual Studio solution.
Disable build parallelization in case there is some weird file locking issue with concurrent project builds. Go to Tools -> Options, Projects and Solutions -> Build and Run, then set "maximum number of parrellel project builds" to 1. Not the best solution but it may help narrow down the problem.
Disable the Hosting Process in case it's locking some file causing an assembly to not get rebuilt correctly. For C# project go to Project Properties, Debug tab, and uncheck "Enable the Visual Studio hosting process". For VB.NET project you'll need to Unload Project, Edit the project file, and add <UseVSHostingProcess>false</UseVSHostingProcess> to the PropertyGroup of each configuration. Again, not the best solution but you probably won't notice a difference.
Lastly, try doing a Clean + Build to try and resolve the issue when it occurs (I know this is not a fix but it's easy enough to do), also Rebuild may be slightly different than Clean + Build so try the latter if the former doesn't work.
As I can not comment due to lack of appropriate points.
But I would like to share one of my experience:
In an aspx.cs page I was working, used to compile fine and some time gave mysterious error of a variable not defined or function not defined or sometime variable or the function defined two times. I changed possibly each and every variable and function name but there seemed no effect , but after entering a simple space or a new line at any place in the file used to solve the compile error. At one time I tried to save the file (in a different encoding as i am used to experiments) and found that the file was not saving in the correct encoding (i.e. the ansi encoding because the file had a unicode character ), I removed the unicode character and that compile error didn't bothered me again.
This unicode character problem could be (not a hard and fast rule) there so you could check it.
Nuke & restore using source control (TFS instructions here):
Make sure you have everything checked in
Exit Visual Studio
Rename the project directory to .Bak (effectively deleting it)
Reopen Visual Studio and in source control:
Get Specific Version
check 'Overwrite... not checked out' and 'Overwrite ... even if local version matches'
Re-open project
Another problem: Make sure some source files are not newer than the current date (or your date is set back). Often this happens in apps where you are doing logic that requires certain things to happen differently on certain dates. You change your clock to test it, make a revision to the source with the date advanced, set the date back, and viola, rebuild does not rebuild that file.
You say 'typing it in again' - can you try just saving? After 40 years since MULTIX the .net build still decides what has changed by checking the file timestamp.
good luck!
When you get the error, is it always on the VB calling C# side, or vice-versa, or does it work both ways?
If the answer is either of the first two situations, try building the "callee" project within the solution before building the "caller" project to see if it stops the situation.
Also, just in case it may jog something for you to think about, does this error crop up when you change a VB file or a C# file, or is there no correllation?
Oh, and sorry this looks like an answer instead of a comment, I cannot post comments yet (need 50 rep).
I've searched all the docs but can't seem to find a single example of using CTEST_CUSTOM_PRE_TEST.
Basically I need to start and run some commands on the server before the test runs. So I need to add a few pre-test steps. What's the syntax of CTEST_CUSTOM_PRE_TEST?
CTEST_CUSTOM_PRE_TEST( ??? what to put here ??? )
ADD_TEST(MyTest MyTestCommand)
CTEST_CUSTOM_PRE_TEST is a variable used in the context of running a ctest dashboard. It should either be set directly in the ctest -S script itself, or in a CTestCustom.cmake file at the top of your build tree.
In either file, an example value might be:
set(CTEST_CUSTOM_PRE_TEST "perl prepareForTesting.pl -with-this -and-that")
It should be a single command line, properly formatted for running on the system you're on. It runs once during a ctest_test call, before all the tests run. Similarly, there is also a CTEST_CUSTOM_POST_TEST variable, that should also be a single command line, but runs after all the tests are done.
Quoting and escaping args with spaces, quotes and backslashes may be challenging ... but maybe you won't need that, either.
I do not know of a real world example of this that I can point you to, but I can read the ctest source code... ;-)
Place set(CTEST_CUSTOM_PRE_TEST .. in a file which during cmake execution is copied to ${CMAKE_BINARY_DIR}/CTestCustom.cmake. For details, see https://stackoverflow.com/a/37748933/1017348.
In OpenSCAD on headless linux we attempt to startup a virtual framebuffer before ctest runs. We don't use PRE_TEST though. We build our own CTestCustom.cmake in the build directory during the 'cmake' run. (We do use POST_TEST, but there were a few recent versions of cmake where POST_TEST was broken)
You can find the code here https://github.com/openscad/openscad/blob/master/tests
This has been asked, but wasn't answered. The answer (use /warn:1) doesn't work for msbuild.exe, only csc.exe. Perhaps I'm missing something between csc and msbuild?
I'd like to suppress all compiler warnings and code analysis warnings (e.g. "The variable 'variableNameHere' is assigned but its value ..." or Code Analysis Warning : CA1805 : Microsoft.Performance : ...) when I'm using command line msbuild. I don't want to alter the solution file. There are several hundred warning messages in the very large solution that I'm building -- fixing them is far out of scope for my project.
I tried /v:quiet but that didn't work.
Is there any way to do this via the command line?
Update: this:
C:\WINDOWS\Microsoft.NET\Framework\v3.5\msbuild.exe C:\Dev\ReallyBigSolution.sln /p:NoWarn=true /p:NoWarn=CA1031
Absolutely doesn't work. I still get hundreds of warnings, including the one I specifically blocked (CA1031).
Using /p:RunCodeAnalysis=Never or /p:RunCodeAnalysis=false apparently doesn't suppress code analysis warnings or errors.
Can use nowarn flag on the compiler, which corresponds to <NoWarn> property in the .csproj file. So maybe msbuild /p:NoWarn="37;68" will turn off those warning numbers (haven't tried it).
Or use
http://msdn.microsoft.com/en-us/library/13b90fz7.aspx
to turn off warnings altogether. I don't know the property name offhand, try /p:Warn=0.
Edit: read the comments toward the end; seems like really getting rid of all these warnings isn't possible.
I know this is an old post but it got me on the right track and by adding the following to my msbuild call it suppressed all of the warnings and output as it built the project. I have this in a batch file so the only output I get I believe are the end results and any messages I prompt with echo. The secret was in the /clp switch. So I looked that up and put in all of the ones that supress output. Each one got rid of more but there were still the yellow warnings coming up and when I added the ErrorsOnly switch, there was no more output.
call msbuild /clp:NoSummary;NoItemAndPropertyList;ErrorsOnly /verbosity:quiet /nologo
Try this:
msbuild.exe C:\Dev\BigSolution.sln /p:WarningLevel=0 /p:RunCodeAnalysis=false
I have tried this and cannot suppress the warnings either, unless I list them out on the /NoWarn property for msbuild.exe
http://social.msdn.microsoft.com/Forums/en-US/tfsbuild/thread/96b3ea2e-92ed-4483-bbfe-a4dda3231eb9
According to this, it cannot be suppressed.
Looks like it is not possible...
Warnings with MSB prefix are thrown by
MSBuild. Currently, we can't suppress
MSBuild warnings.