I am planning to use StyleCop in my project. My requirement is that the project should not get compiled when StyleCop returns a warning. Nor debugging should be possible.
I have already integrated StyleCop into MSBuild as described at http://blogs.msdn.com/b/sourceanalysis/archive/2008/05/24/source-analysis-msbuild-integration.aspx. It is throwing errors when I build. But, when I start debugging, it is possible (Means, it is possible for programmer to override StyleCop). I can see that the build process is not getting cancelled and all dlls are created.
Is it possible to cancel the build when StyleCop throws errors ?
Thanks,
Madhu
to show warnings of StyleCop as errors you can add next line into your *.csproj file:
<StyleCopTreatErrorsAsWarnings>false</StyleCopTreatErrorsAsWarnings>
to avoid compiling with stylecop errors you can use StyleCop's target just adding a line into same project file:
<Import Project="$(SolutionDir)\LOCAL_PATH\Microsoft.StyleCop.targets" />
After adding this line you will not compile project with StyleCop warnings(errors).
Related
I have configured a TFS(2017) build pipeline to compile a VS extension with debug mode for a specific requirement which require .pdb files.
The build solution task fails for "debug" configuration with below error, however same pipeline works for the release configuration.
I have tried the approach mentioned in the following discussion as well, howewer it doesn't resolve my issue.
https://social.msdn.microsoft.com/Forums/vstudio/en-US/fd220999-5761-475a-bf86-98dff6b35218/unable-to-compile-vsix-project-that-is-a-part-of-my-solution-using-amd64-msbuild-from-vs2015?forum=msbuild
Appreciate if someone can help me to resolve this issue.
Following is the build configuration used for the Build Solution task:
Following build variables are used to configure build parameters.
Build Error message:
packages\Microsoft.VSSDK.BuildTools.15.1.192\tools\VSSDK\Microsoft.VsSDK.targets
(633, 5)
packages\Microsoft.VSSDK.BuildTools.15.1.192\tools\VSSDK\Microsoft.VsSDK.targets(633,5):
Error VSSDK1077: Unable to locate the extensions directory. "Value
cannot be null. Parameter name: path1". Process 'msbuild.exe' exited
with code '1'.
Update your Microsoft.VSSDK.BuildTools NuGet package to latest version 15.9.3032, just in case it is a problem already solved.
Release configurations can also generate PDB files (Project properties, Build tab, Advanced...button, Output > Debugging information). So, if the Release configuration works for you, you can keep using it while also generating a pdb file with full debug information.
The error is happening when, once compiled correctly, the generated VSIX output file is going to be deployed to the folder for extensions of the experimental VS instance, which is a required step to debug the VSIX file. A possible explanation of the different behavior for Debug/Release configurations is that maybe your .csproj specifies <DeployExtension>False</DeployExtension> for the Release configuration. By default, if not set, that property is set to true in the Microsoft.VsSDK.targets file:
<DeployExtension Condition="'$(DeployExtension)' == ''">true</DeployExtension>
Since likely you don't need to deploy the VSIX to the VS experimental instance when building on a build server (because you are not going to debug it), you can set that property to False to skip the deployment. This can be done with a 3rd build configuration (ex: "DebugBuildServer"), for which you specify DeployExtension to False in the .csproj file, or sticking to two build configurations but passing the /p:DeployExtension=false in the MSBuild arguments of the Visual Studio Build task of your build pipeline.
Microsoft's instructions for enabling debugging of MSBuild tasks no longer seem to work. I cannot get msbuild /? to show the /debug switch, and when I try dotnet publish /debug it complains that /debug is not a valid switch.
Is there any way to debug MSBuild tasks any more?
The /debug feature for msbuild was removed from public builds of MSBuild 15 and the code for it has later been removed entirely.
To "debug" logic in your build targets / msbuild files, your best option is to create binary logs using the -bl argument and inspecting them using the MSBuild Structured Log Viewer. It shows you all the inputs/outputs to task invocation and all the steps that happen during Msbuild runs.
Debugging custom tasks (e.g. C# code) is very hard to do. It would involve looping+sleeping until Debugger.IsAttached is true for debug builds (and then attaching to the process in Visual Studio) or calling Debugger.Launch() (only on .NET Framework, not .NET Core MSBuild).
I suggest separating the actual task class from your logic implementation to allow you to unit test your logic. This should remove the need to debug it during runs.
You can see a sample of both the debugger logic and the separation in NuGet's PackTask and its PackTaskLogic class.
I have looked high and low for the solution to this, and I have gotten close, but still having a little trouble.
The error:
Build: Experimental support for decorators is a feature that is subject to change in a future release. Specify '--experimentalDecorators' to remove this warning.
This error appears for every usage of decorators. I have the MSBuild set up with
<TypeScriptEmitDecoratorMetadata>True</TypeScriptEmitDecoratorMetadata>
<TypeScriptExperimentalDecorators>True</TypeScriptExperimentalDecorators>
and that removed half of the errors (compiler errors, not build errors). However, now I'm stuck with the build errors. The .ts files still get compiled to .js, no problem.*** But the exceptions get in the way of building the rest of the solution.
If any of this doesn't make sense, please let me know. I'm not the best with words.
Edit: I discovered that the .js is created upon save, not build. So anything relating to build is "broken."
I had the same problem. I ended up modifying the .csproj to change all TypeScriptCompile elements to just plain Content elements, and I used my own compile task (via Gulp).
For example,
<TypeScriptCompile Include="app.ts" /> became <Content Include="app.ts" />.
I also removed any imports that referenced Typescript related MSBuild targets, i.e. <Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.targets" Condition="Exists('$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.targets')" />
I still get IDE (and Resharper, if you use that) support for Typescript - I just explicitly tell Visual Studio not to handle any TS compilation for my project. It seems that the only downside is having to manage my Gulp tasks for compiling the Typescript. Using Task Runner Explorer extension for VS, adding the Gulp compilation task as part of the project's build, or just using the Gulp task inside of a gulp watch can mitigate the tradeoff.
I am trying to make a build script for a .NET solution which consists of several c# projects and one custom project. The custom project can be build by devenv but msbuild chokes on it.
I would like MSBuild to ignore the custom project because I'm already building it with an Exec task. I actually need MSBuild to not even open the custom .proj file because it's in JSON format and thus causes MSBuild to crash out.
The /BuildProjectReferences=false switch doesn't work. MSBuild still tries to read the custom project file. Is there any way around this?
This question stemmed from a project which had a SilverFrost Fortran project alongside several c# class libraries. The solution would only compile using devenv. Msbuild would throw an error on the Fortran project because it doesn't use the standard .csproj format.
Even with /BuildProjectReferences=false, msbuild would try to read the Fortran project and throw an error. The workaround I discovered was to wrap the msbuild task in an nant task which does the following:
Invokes the Fortran command line compiler
Removes all references to the Fortran project from other .csproj projects using the xmlpoke task
Replaces said references with a direct dll reference to the Fortran compiler output
Invokes Msbuild on the modified solution
Instead of building your solution once by MSBuild, try to build each project one by one. In this case, you can ignore the desired project. You can also define your own "Exec"-based build in this new script.
In your project that uses the custom project, can you right click on the Project Dependencies and remove the custom project from the list? You can refer to the custom project's binary output instead.
I am using StyleCop 4.4.0 RTW. I have installed it, copied the contents to a version controlled directory and I've added it to each of my project files by simply adding this line to each .csproj-file:
<Import Project="..\Library\StyleCop\v4.4\Microsoft.StyleCop.targets" />
The basic functionality seems to work. When I Build a project in Visual Studio I get:
------ Build started: Project: MyProject.Core, Configuration: Debug Any CPU ------
C:\Windows\Microsoft.NET\Framework\v3.5\Csc.exe /noconfig /nowarn:1701,1702 /errorreport:prompt /warn:4 /define:DEBUG;TRACE /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Data.dll /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.dll /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.EnterpriseServices.dll /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Web.Services.dll /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Xml.dll /debug+ /debug:full /filealign:512 /keyfile:..\Build\myproject.snk /optimize- /out:obj\Debug\MyProject.Core.dll /target:library Controller\AcceptAllAccessController.cs Controller\NoSearchSessionSpecifiedException.cs Controller\DenyAllAccessController.cs Controller\SearchContextExpiredException.cs Controller\SearchEngineFacade.cs Environment\ConnectionSettings.cs Environment\IAccessController.cs Environment\ICache.cs Model\Age.cs Model\Bet.cs Model\Category.cs Model\CategoryGroup.cs Model\Click.cs Model\DateTimeInfo.cs Model\DateTimeRange.cs Model\FileFormat.cs Model\FileFormatCollection.cs Model\Hit.cs Model\Language.cs Model\MetaAttributes.cs Model\QueryCompletionResponse.cs Model\QueryRefinement.cs Model\SearchContext.cs Model\SearchFilter.cs Model\SearchFilterCollection.cs Model\SearchRequest.cs Model\SearchResponse.cs Model\Session.cs Model\SortOrder.cs Model\SpellingSuggestion.cs Properties\AssemblyInfo.cs Util\HexEncoding.cs Util\ParameterConv.cs Util\StringUtil.cs "Web References\WebService\Reference.cs"
Compile complete -- 0 errors, 0 warnings
MyProject.Core -> C:\Users\kentl\Documents\Visual Studio 2008\Projects\WebToWebForms\MyProject.Core\bin\Debug\MyProject.Core.dll
Controller\AcceptAllAccessController.cs(15,1): warning : SA1508: A closing curly bracket must not be preceded by a blank line.
Done building project "MyProject.Core.csproj".
========== Build: 1 succeeded or up-to-date, 0 failed, 0 skipped ==========
I get PROJECTDIR\obj\Debug\StyleCopViolations.xml containing the violations.
I would like to ONLY get the StyleCop information in the output file. I do not want a warning or error. If it is possible, how do I configure it to work like that?
You can't. There is no setting available in StyleCop task to have only the output file and no warnings or errors.
Possible solutions :
Create a Custom MSBuild Logger that will filter StyleCop log (More on info on MSBuild logger).
Create a Custom task doing the same thing than StyleCop one but without logging warning and error in console (More info on custom task).
Ask for the feature or do it yourself (StyleCop opensource project)
If you open the Project Solution Folder in which StyleCop has run, there you can find one file named as StyleCop.Cache. This file contains the output of StyleCop. If you wanna see the output of StyleCop, Just you will have to open it in the Notepad.