I want to exclude /Properties/AssemblyInfo.cs from stylecop checking.
Can we do that?
the problem is that i have integrated stylecop with nant. In nant i am stamping product version so the information from Assembly info changes and it gives warning in nant email. I am using stylecopcmd
for nant integration.
There are a couple of ways to do this. The recommended method is with file lists. Here is an example:
<StyleCopSettings Version="4.3">
<SourceFileList>
<SourceFile>AssemblyInfo.cs</SourceFile>
<Settings>
<GlobalSettings>
<BooleanProperty Name="RulesEnabledByDefault">False</BooleanProperty>
</GlobalSettings>
</Settings>
</SourceFileList>
</StyleCopSettings>
Alternatively you can use the ExcludeFromStyleCop setting in the project file as documented here:
<Compile Include="AssemblyInfo.cs">
<ExcludeFromStyleCop>true</ExcludeFromStyleCop>
</Compile>
Related
A project I'm working on has a csproj file with Pre/Post build events that only run when its being built in Visual Studio. It looks like this:
<Target Name="PreBuild" BeforeTargets="PreBuildEvent" Condition="'$(BuildingInsideVisualStudio)' == 'true' ">
<!-- Pre build stuff -->
</Target>
Is there an equivalent condition for when a project is being built inside Rider, something like '$(BuildingInsideRider)'?
I reached out to Jetbrains support with the same question, and they told me the property name is '$(BuildingByReSharper)'. It's also worth noting that it's only useable in Rider 2021.1.3 and newer.
I am trying to use VS2012 dynamic code coverage tool to do code coverage analysis for my application.
I find an example that I can use it like follows:
CodeCoverage.exe collect /output:C:\test.coverage c:\aut.exe
This works well however, my aut.exe will load many dlls and I simply don't want to get code coverage information for every dll. So I need to modify the CodeCoverage.config file in VS2012 dynamic code coverage Tools folder to only include some dlls I want.
I look at the config file, it looks like:
<SymbolSearchPaths />
<!--
The module include/exclude list by the full path from where the module loaded.
Entries in this list are case-insensitive.
-->
<ModulePaths />
This file is a little bit different with the previous .runsettings file. I tried adding following code in the config file:
<ModulePaths>
<Include>
<!-- Include modules of interest, by their name / path -->
<ModulePath>SomeSpecial.dll</ModulePath>
</Include>
<Exclude>
<!—- Do not specify any excludes. Anything not included will get excluded -->
</Exclude>
</ModulePaths>
But it did not work. I guess the grammar here is a little different with the .runsetting file.
So can anyone guide me on how to modify the codecoverage.config file to only include specific dlls for code coverage?
OK, I finally solved the problem myself...
Actually there is a way to only include some dlls for code coverage. I should use regular expressions when defining the module path for include.
For example:
<ModulePaths>
<Include>
<ModulePath>.*SomeSpecial\.dll$</ModulePath>
<ModulePath>.*Special\.dll$</ModulePath>
</Include>
</ModulePaths>
The key is add ".*" before your dll name and add "\" before "." because the node for Module path here only allows for regular expression. Using this method, I successfully include the dlls I want for code coverage.
I'm trying to get Visual Studio 2013's msbuild .vcxproj to automatically mark certain .cpp project files as <ExcludedFromBuild>true</ExcludedFromBuild> based on the .cpp filename.
My goal is to allow my program (~100 developers, ~1000 vcxproj) to easily support Debug only compilations of unit test code, that would all be written in .cpp files that had a _utest.cpp suffix. Any .cpp files that ended in _utest.cpp would be automatically excluded from a release build, and the programmer could see that in Visual Studio's Solution Explorer when they were switched to a Release Solution Configuration.
I have been able to prevent the _utest.cpp-suffixed files from building in Release by adding this to my shared .props file
<Target Name="Remove _utest.cpp" BeforeTargets="ClCompile" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ItemGroup>
<ClCompile Remove="*_utest.cpp" />
</ItemGroup>
</Target>
but that doesn't give a visual indicator in Solution Explorer that the files are not part of the Release build.
I already tried a condition in an ItemDefinitionGroup that was based on %(Identity) but that didn't work
<ItemDefinitionGroup Condition="'%(Identity)'=='throttle_utest.cpp'">
<ClCompile Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ExcludedFromBuild>true</ExcludedFromBuild>
</ClCompile>
</ItemDefinitionGroup>
(Visual Studio refused to load this one with an error "The reference to the built-in metadata Identity at position 1 is not allowed")
or
<ItemDefinitionGroup Condition="$([System.Text.RegularExpressions.Regex]::IsMatch(%(Identity), '_utest\.cpp$'))">
<ClCompile Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ExcludedFromBuild>true</ExcludedFromBuild>
</ClCompile>
</ItemDefinitionGroup>
(Visual Studio loaded with this change, but did nothing to exclude the matching files from building).
Is there a way I can conditionally exclude files based on filename and get a visual indicator in Solution Explorer?
I think something like this should work.
Right under the <Project> tag.
<ItemGroup Condition="'$(Configuration)'!='Debug'">
<ClCompile Include="*_utest.cpp">
<ExcludedFromBuild>true</ExcludedFromBuild>
</ClCompile>
</ItemGroup>
This works for me (was done entirely in VS2013 UI - right-click on Properties of source file and select Excluded from build: True for Release Configuration):
<ClCompile Include="foo_utest.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">false</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
NOTE: According to https://learn.microsoft.com/en-us/cpp/ide/vcxproj-file-structure?view=vs-2017 :
The Visual C++ project system currently does not support wildcards in project items.
For example, this is not supported:
<ClCompile Include="*.cpp"/>
Therefore each file should be excluded individually.
I have solution in Xamarin.iOS with project that references very large DLL (binding for very large native library). So build time for solution is very large. After simple modification in any source file I need to wait for linking. So my idea was to exclude the reference from project using custom property and also to make define that I will use in .cs files to exclude code that depends on large assembly. But I'm unable to use custom condition to exclude the reference. The following strategy will not work for Xamarin.iOS (but will work in Visual Studio):
Create file CommonProperties.prop:
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<LinkWithLargeAssembly>True</LinkWithLargeAssembly>
</PropertyGroup>
</Project>
So the idea is: When it is not critical I can define LinkWithLargeAssembly as False and link my project fast. CommonProperties.prop can be imported in any assembly that depends on features of the large library.
In the project file .csproj import above file and try to exclude reference (for example monotouch):
...
<Import Project="CommonProperties.prop" />
...
<ItemGroup>
<Reference Include="monotouch" Condition=" '$(LinkWithLargeAssembly)' == 'True' " />
</ItemGroup>
...
I've tried also to define property $(LinkWithLargeAssembly) directly in the project file without import. Also I've tried to use already defined properties for example $(RootNamespace) and $(AssemblyName). But Condition attribute works only for properties $(Configuration) and $(Platform). That is following code will include and exclude monotouch depending on the configuration:
<ItemGroup>
<Reference Include="monotouch" Condition=" '$(Configuration)' == 'Debug' " />
</ItemGroup>
Is it possible to customize assembly reference including using my own conditional properties?
I solved the problem by adding new build configuration that was copied from Debug. I named it DebugNoLargeLib. So I can exclude reference with the following code because $(Configuration) property will be parsed correctly:
<ItemGroup>
<Reference Include="SomeLargeLib.dll" Condition=" '$(Configuration)' != 'DebugNoLargeLib' " />
</ItemGroup>
After I added preprocessor directive NO_LARGE_LIB to the Compiler section for configuration DebugNoLargeLib.
So now I'm able to link without large library and exclude code depending on it from compilation.
But I think this is mistake from Xamarin side that project files processing is not fully supported according to Microsoft specs.
I've got a web project using TypeScript that has some reasonably complex requirements for the compiled output files. So for instance, I need all the *.ts files in one directory to compile down to one single .js file, and all the *.ts files in another directory to compile down to a different .js file. (It's more complex than that, but you get the idea.)
I've been able to get this working using the tsc.exe command-line, using input files and what-not, but I'd like to be able to use MSBuild .targets files - among other things, using tsc.exe from the command-line seems to be pretty poorly supported on continuous integration servers, where it can be located who-knows-where, and certainly isn't likely to be in the path.
According to this answer here, it seems like I should be able to do this using custom build targets. So I've created a custom version of Microsoft.TypeScript.targets, and in addition to the default "CompileTypeScript" target, I've created a second one, "PayboardApiV10", so that the relevant part looks like so:
<Target Name="CompileTypeScript" Condition="'$(BuildingProject)' != 'false'">
<Message Text="Compiling TypeScript files normally" Importance="high"/>
<VsTsc
ToolPath="$(TscToolPath)"
ToolExe="$(TscToolExe)"
Configurations="$(TypeScriptBuildConfigurations)"
FullPathsToFiles="#(TypeScriptCompile)"
YieldDuringToolExecution="$(TscYieldDuringToolExecution)"
OutFile="$(TypeScriptOutFile)"
OutDir="$(TypeScriptOutDir)"
>
<Output TaskParameter="GeneratedJavascript" ItemName="GeneratedJavascript" />
</VsTsc>
</Target>
<Target Name="PayboardApiV10" Condition="'$(BuildingProject)' != 'false'">
<Message Text="Compiling TypeScript files for Payboard API v1.0" Importance="high" />
<VsTsc
ToolPath="$(TscToolPath)"
ToolExe="$(TscToolExe)"
Configurations="$(TypeScriptBuildConfigurations)"
FullPathsToFiles="#(TypeScriptCompile)"
YieldDuringToolExecution="$(TscYieldDuringToolExecution)"
OutFile="Payboard.js"
OutDir="$(ProjectDir)api\v1.0\"
>
<Output TaskParameter="GeneratedJavascript" ItemName="GeneratedJavascript" />
</VsTsc>
</Target>
And then I've specified a "CustomTool" in my project configuration for the specific files that I'd like to get picked up by the "PayboardApiV10" build target, like so:
I should note that I have no idea if I'm doing this bit correctly. I can't seem to find any documentation on it, and the only examples I've been able to find are from that previous answer. And more to the point, when I run my builds, all the TS files in my project get caught up in the first build target, including the ones for which I've specified "MSBuild:PayboardApiV10" for the custom tool. The "PayboardApiV10" tool never seems to get run, i.e., I never see the message "Compiling TypeScript files for Payboard API v1.0".
So two questions:
(1) Is there a better way to do what I'm trying to do?
(2) If this is generally the right way to do it, any ideas as to what I'm doing wrong?
The direction you're going is the optimal way (on save). In the meantime you can use post-build events to transform the typescript. Right click on your project and select properties. Select Build Events and in the Post-Build area you can specify command line parameters to use tsc.exe.
On the direction you're going (compile on save) I think the project file may be missing the following on each file you want compiled:
<TypeScriptCompile Include="app.ts" />
The configuration is also likely missing the environment settings.
<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
<TypeScriptTarget>ES5</TypeScriptTarget>
<TypeScriptIncludeComments>true</TypeScriptIncludeComments>
<TypeScriptSourceMap>true</TypeScriptSourceMap>
</PropertyGroup>
More information on both methods is available at this TypeScript wiki page.
I ended up asking this same question over on the TypeScript forums (https://typescript.codeplex.com/discussions/455781). The conclusions I drew from the conversation there:
There isn't a great way to do it now.
The best hacky way to do it now is probably the way that I was doing it, namely, with batch files, post-build events, and checking the compiled files into source. Other folks recommended Grunt, or the ASP.NET MVC bundling mechanism (the latter won't work in my scenario); I've also used the r.js minifier in the past. And these will work; but to reiterate, none of these are really very good solutions.
The best way to do it in the future will be to create "library projects" of TypeScript files, so that all TS files in a given project get compiled together; and then you can reference the library TS projects from your main Web project, and will automatically get the compiled files merged into your main ~/Scripts folder. But that will require support from the TS team - which Jon Turner basically indicated would be coming, though he didn't say when. (See also https://typescript.codeplex.com/workitem/571.)