问题标签 [csproj]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
2 回答
477 浏览

regex - 如何使用正则表达式分割嵌入 .csproj 文件中的 xcopy 语句?

我正在处理一堆(~2000).csproj 文件,在这个开发人员中,有一个历史先例是在构建后事件中嵌入 xcopy 以在构建过程中移动东西。为了将构建知识集中到一个地方,我正在努力消除这些 xcopy 调用,以支持我们的自动化构建过程中的声明性构建操作。

考虑到这一点,我试图想出一个正则表达式,我可以用它来删除提供给 xcopy 的路径参数。这些陈述有几种风格:

具体来说:

  • 不可预知的开关位置
  • 并不总是提供目标路径参数
  • 路径参数有时用引号括起来

我不是正则表达式向导,但这是我到目前为止所得到的(过度使用 parenteses 是为了在 powershell 中保存匹配:

(.*x?copy.* '"?)([^ /'"]+)('"/.* '"?)([^ /'"]+)('"?.*)

这些([^ /'"]+)部分是我打算成为路径参数的部分,被定义为不包含引号、空格或正斜杠的字符串,但我觉得我必须应用两个正则表达式(一个用于带空格的引号包裹的路径一个用于无引号路径)

不幸的是,当我运行这个正则表达式时,它似乎为我提供了第一个和第二个路径参数的相同匹配。最令人沮丧。

我将如何改变它来纠正它?

0 投票
2 回答
1913 浏览

visual-studio - VS2010 project -- unresolved references (where HintPath property missing)

We are in the process of changing our build computer to a new one and at the same time to Visual Studio 2010. We have around 500 different small components, each one an own csproj file, all of them having references to assemblies in a "\Framework\bin\" directory.

After getting the whole source code and starting compiling our projects, we've ran into a problem: many references cannot be resolved, but not all of them, and not always the same references on different projects. The problem seems to be linked to the HintPath attribute of the csproj files.

Specifically, here's an example for a reference that can be resolved:

And here's one that can't:

Strangely, the properties of the two references in Visual Studio are exactly the same (except for their Name and Identities, of course). So it seems that HintPath is auto-generated, but why only on some references?

We suspect the problem could arise from using different version of Visual Studio (of the 500+ projects, some are in VS2005, others in VS2008, others still in VS2010), but we could not narrow the behaviour down to something logical.

Is there any way to compile our projects without having to resort to manually reattach the unresolved references?

0 投票
1 回答
443 浏览

c# - 使用 XDocument 读取 csproj 时检索此 XElement 的更好方法是什么?

我正在将文件添加到 vs.net 之外的 cs 项目(图像、css 等,我们组之外的文件,但对于发布是必需的)。我正在加载 csproj 并查询包含“内容”节点的 ItemGroup。

有没有更好的方法来获得这个组?

谢谢你。

0 投票
2 回答
215 浏览

visual-studio - how can I figure out the output of a c# project file (.csproj)

I have a very large .NET solution with hundreds of projects (all c#) how can I figure out which of the projects is the application project to set as the start up project.

I was thinking of grepping the csproj files for some keyword that indicates it's an executable.

Thank you

0 投票
1 回答
33752 浏览

c# - 项目参考条件包含多个条件

这是我的 csproj 文件中的一个片段:

我想做的是包含program_data.dll多个构建配置,例如,发布和调试。

我尝试执行以下操作

但是 Visual Studio 对此感到窒息。

有没有办法可以做到这一点,或者我必须<ProjectReference>为每个构建配置单独设置一个?

0 投票
2 回答
5562 浏览

powershell - 为 nuget 创建自定义 powershell 脚本,将自定义目标添加到 csproj BeforeBuild 步骤

我想创建一个 nuget 包,使用我创建的自定义 MSBuild 任务将 BeforeBuild 步骤添加到我的 csproj。理想情况下,我想:

  1. 将新目标添加到 csproj 文件 (MyCustomBeforeBuildTarget)
  2. 添加 BeforeBuild 目标(如果它不存在)
  3. 编辑 BeforeBuild DependsOnTargets 属性以包含我的自定义目标

所以安装后我的 csproj 应该有以下内容:

此外,如果我的包被删除,自定义目标也会消失,这会很好,尽管我添加了一个条件,如果我的自定义任务 DLL 不存在,它应该忽略目标。

我可以编写的最简单的 Powershell nuget 安装脚本是什么,它将添加我的自定义目标?我感觉这里的 PowerShell 脚本可能是解决方案的一部分,但我没有足够的 PowerShell 经验来知道如何实际使用它们来编辑 csproj。

0 投票
5 回答
50371 浏览

c# - .csproj 文件有什么作用?

通常,C# 项目有一个与之关联的 .csproj 文件。那个文件是干什么用的?它包含哪些数据?

0 投票
2 回答
1654 浏览

visual-studio - 如何(实际上)在 MonoTouch 中重用现有的 .NET 库

假设我在 Visual Studio 2010 中构建了一个现有的 .NET 程序集,该程序集在其他一些 Winforms 产品中使用。它没有第三方依赖项。

我想在 MonoTouch 解决方案中直接重用该库。

就目前而言,为了能够从我的 MonoTouch UI 项目中添加对我的库的引用,我必须创建一个新的 csproj 文件并创建指向其中所有源文件的链接。

这可行,但会带来维护负担。一定会有更好的办法?

提前致谢。

0 投票
2 回答
1803 浏览

c# - 如何在 PostBuildEvents 之前先运行 app.config 转换任务?

我有一个控制台应用程序,它使用在 app.config 中定义的数据库连接字符串。我有一些转换来根据构建配置更改字符串。

我还有一些将 app.config 复制到其他项目输出的构建后事件。问题是构建后事件首先触发,我复制了未转换的 app.config。后来转换任务开始并应用转换(所以我知道它有效)。我使用 Visual Studio 2010 和 .NET 4。

现在动作是 [1]、[ 3 ]、[ 2 ],我需要将它们重新排序为 [1]、[2]、[3]

1) 构建
2) 运行转换
3) 运行构建后事件

这是我从 .csproj 的转变

这是我的后期制作活动

任何帮助将不胜感激

0 投票
1 回答
16465 浏览

c# - 根据项目配置更改 csproj OutputType

我需要根据项目的配置将 C# 项目构建为 WinExe 或库。

我试过这两种方法都没有运气:

1) 在一般的 PropertyGroup 中:

<OutputType Condition=" '$(Configuration)' == 'Release' ">WinExe</OutputType> <OutputType Condition=" '$(Configuration)' == 'Debug' ">Library</OutputType>

2) 在有条件的 PropertyGroup 中:

<PropertyGroup Condition=" '$(Configuration)' == 'Release' "> <OutputType>WinExe</OutputType> </PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Debug' "> <OutputType>Library</OutputType> </PropertyGroup>

这些方法都不起作用,并且 OutputType 始终是 WinExe。奇怪的是,如果我将 WinExe 的所有实例更改为 Library,那么它始终是 Library。这让我觉得它正在成功地阅读它们,但要么以奇怪的顺序,要么 WinExe 优先于库。

有任何想法吗?