Trong sản phẩm của chúng tôi, có khoảng 400 dự án, vì vậy trong VS 2012, nếu tôi muốn xây dựng thì nó sẽ tạo phân tích mã cho tất cả 400 dự án và tôi không thể tự động tắt phân tích mã cho từng dự án &. Vì vậy, tôi đang tìm kiếm một cơ chế vô hiệu hóa việc phân tích mã cho toàn bộ giải pháp (tất cả các dự án) thay vì áp dụng các thiết lập đó cho các dự án riêng lẻ.Vô hiệu hóa phân tích mã ở mức giải pháp trong Microsoft Visual Studio 2012
Trả lời
Không chắc chắn có dễ dàng thực hiện việc này với VS2012. CodeAnalysis được định nghĩa ở cấp dự án và phụ thuộc vào cấu hình xây dựng của bạn. Ví dụ, không có phân tích mã trong Release.
Trước tiên, hãy thử tạo cấu hình dựa trên Bản phát hành.
Một giải pháp khác (nhưng rất tệ) có thể là chạy hàng loạt để sửa đổi tất cả các tệp dự án của bạn.
Đây là một tập tin dự án mẫu (kiểm tra các yếu tố được đặt tên RunCodeAnalysis):
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<RunCodeAnalysis>false</RunCodeAnalysis>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
Cảm ơn bạn đã trả lời ... !!! ... Nhưng tôi biết những thay đổi ở cấp độ dự án nhưng tôi muốn vô hiệu hóa ở cấp độ giải pháp hoặc nói cho tất cả các dự án chỉ trong một thiết lập ... – Nirav31
Bạn có thể viết một ứng dụng giao diện điều khiển nhỏ mà đọc tất cả các file dự án ra khỏi một tập tin giải pháp và sau đó chuyển đổi các Xml Nút của từng dự án.
Chức năng để có được các tập tin dự án ra khỏi dung dịch:
public IEnumerable<string> Parse(string solutionFile)
{
if (solutionFile == null)
throw new ArgumentNullException("solutionFile");
if (!File.Exists(solutionFile))
throw new FileNotFoundException("Solution file does not exist", solutionFile);
var projectFiles = new List<string>();
using (var reader = new StreamReader(solutionFile, true))
{
while (!reader.EndOfStream)
{
var line = reader.ReadLine();
if (line == null)
continue;
line = line.TrimStart();
if (!line.StartsWith("Project(", StringComparison.OrdinalIgnoreCase))
continue;
var projectData = line.Split(',');
var projectFile = projectData[1].Trim().Trim('"');
if (!string.IsNullOrEmpty(Path.GetExtension(projectFile)))
projectFiles.Add(projectFile);
}
}
return projectFiles;
}
Và chức năng để chuyển RunCodeAnalysis Node (s):
public void ToggleCodeAnalysis(string projectFile)
{
if (projectFile == null)
throw new ArgumentNullException("projectFile");
if (!File.Exists(projectFile))
throw new FileNotFoundException("Project file does not exist", projectFile);
var xmlDocument = new XmlDocument();
xmlDocument.Load(projectFile);
var namespaceManager = new XmlNamespaceManager(xmlDocument.NameTable);
namespaceManager.AddNamespace("ns", "http://schemas.microsoft.com/developer/msbuild/2003");
var nodes = xmlDocument.SelectNodes("//ns:RunCodeAnalysis", namespaceManager);
if (nodes == null)
return;
var hasChanged = false;
foreach (XmlNode node in nodes)
{
bool value;
if (!Boolean.TryParse(node.InnerText, out value))
continue;
node.InnerText = value ? "false" : "true";
hasChanged = true;
}
if (!hasChanged)
return;
xmlDocument.Save(projectFile);
}
Bạn có thể sử dụng một chút lừa để vô hiệu hóa phân tích mã tĩnh cho toàn bộ trường hợp Visual Studio như được mô tả here. Nói tóm lại:
- Mở
Developer Command Prompt for VS2012
- loại
set DevDivCodeAnalysisRunType=Disabled
- loại
devenv
để bắt đầu Visual Studio
giải pháp Cùng làm việc cho Visual Studio 2015 qua Developer Command Prompt for VS2015
.
Bạn có thể sử dụng cửa sổ Trình quản lý gói của Nuget để thực hiện điều đó.
Tạo một tập tin văn bản mới trong thư mục "C: \ Users {user của bạn} \ Documents \ WindowsPowerShell" có tên là "NuGet_profile.ps1" và thêm đoạn mã sau:
function Disable-CodeAnalysis(){
ForEach ($project in $dte.Solution.Projects) {
Set-CodeAnalysis($project, $false)
}
}
function Enable-CodeAnalysis(){
ForEach ($project in $dte.Solution.Projects) {
Set-CodeAnalysis($project, $true)
}
}
function Set-CodeAnalysis($project, $value){
$projectName = $project.Name
$projectFilePath = $project.FullName
if ([System.String]::IsNullOrWhiteSpace($projectFilePath)){
if($proj.Kind -eq "{66A26720-8FB5-11D2-AA7E-00C04F688DDE}"){
ForEach ($item in $proj.ProjectItems) {
if($item.SubProject -ne $null){
Set-CodeAnalysis($item.SubProject, $value)
}
}
}
continue;
}
$xmlDocument = new-object System.Xml.XmlDocument
$action = "Enable"
if($value -ne $true){
$action = "Disable"
}
Write-Host "$action code analysis for $projectName at $projectFilePath"
$xmlDocument.Load([string]$projectFilePath);
$namespaceManager = new-object System.Xml.XmlNamespaceManager($xmlDocument.NameTable);
$namespaceManager.AddNamespace("ns", "http://schemas.microsoft.com/developer/msbuild/2003");
$nodes = $xmlDocument.SelectNodes("//ns:RunCodeAnalysis", $namespaceManager);
if ($nodes -eq $null){
continue;
}
foreach ($node in $nodes){
$node.InnerText = "$value";
}
$xmlDocument.Save($projectFilePath);
}
Khởi động lại Visual Studio. Nhấp vào menu "Xem" | "Các cửa sổ khác" | "Package Manager Console". Bây giờ bạn có thể thực hiện các lệnh sau:
> Enable-CodeAnalysis
> Disable-CodeAnalysis
Để vô hiệu hóa phân tích mã cho dự án cụ thể: -
- Nhấp chuột phải vào Project, chọn Properties.
- Trên trang thuộc tính, chọn Phân tích mã.
- Bỏ chọn hộp kiểm "Bật phân tích mã trên bản dựng".
- 1. Disable Phân tích Mã trong Visual studio 2012
- 2. Vô hiệu hóa cảnh báo Qt trong Visual Studio 2008
- 3. Visual Studio 2012 bị treo khi đóng giải pháp
- 4. Visual Studio 2010 không thể mở một giải pháp 2010 Visual Studio 2012 sửa đổi
- 5. Microsoft Visual Studio 2012 đã ngừng hoạt động
- 6. CA1001 Visual Studio 2012 Cảnh báo phân tích mã. Nó có nghĩa là gì?
- 7. Trình đơn Visual Studio 2012 'phân tích mã bảo mật' bị thiếu
- 8. Giải pháp tự động hóa Visual Studio Build
- 9. Vô hiệu hóa đổi tên id tự động Visual Studio
- 10. Microsoft Visual Studio 2012 dòng lệnh rất nhỏ
- 11. Tắt tự động lưu mã trong Visual Studio 2012
- 12. Vô hiệu hóa phân tích mã cho tệp hiện tại trong ReSharper
- 13. Vô hiệu hóa PostgreSQL 8.4 tsvector phân tích cú pháp của 'file` thẻ loại
- 14. Phân tích mã bị thiếu từ Visual Studio 2008
- 15. Làm thế nào để vô hiệu hóa hình ảnh "chấm" trong Visual Studio Editor
- 16. Ngăn chặn phân tích mã từ xây dựng lại dự án và phụ thuộc trong Visual Studio 2012
- 17. "không thể phân giải thẻ svg" với html5 trong Visual studio 2012
- 18. Cách đồng bộ hóa cửa sổ mã và trình khám phá giải pháp trong Visual Studio?
- 19. Dự án Visual Studio 2010 cho Visual Studio 2012
- 20. Visual Studio Giải pháp lớn
- 21. Vô hiệu hóa thiết kế cho một lớp dẫn xuất trong Visual Studio 2008
- 22. Vô hiệu hóa trình biên dịch nền Visual Basic trong Visual Studio 2008
- 23. Lỗi trình phân tích cú pháp Microsoft ASP.NET ReportViewer
- 24. ở đâu là _mm_prefetch trong Visual Studio 2012?
- 25. Vô hiệu hóa cặp thẻ Html của Visual Studio 2010 Chỉnh sửa
- 26. Giải pháp Visual Studio trong Qt Creator
- 27. Phân tích mã Visual Studio vs StyleCop + FxCop
- 28. Visual Studio 2012 "Tìm trong tệp" tìm kiếm vượt xa giải pháp khi "Toàn bộ giải pháp" được chỉ định
- 29. Làm thế nào để vô hiệu hóa định dạng Javascript/HTML điên trong Visual Studio 2008?
- 30. Visual Studio 2012 - Tìm Tham khảo Thông tư hiệu quả
Tất cả các dự án đó có nằm trong một giải pháp không? –
Có, bởi vì chúng tôi cũng có các trường hợp thử nghiệm đơn vị được kết hợp với chúng. – Nirav31
400 dự án trong một giải pháp là quá nhiều –