尝试使用ServiceController时出现错误MSB4062
我在x64机器上使用Visual Studio 2010和TFS 2010.
I use Visual Studio 2010 with TFS 2010 on a x64 machine.
我正在尝试在构建中使用MSBuild社区任务目标.此目标存在于源代码管理中.因此,在我的csproj文件中,我导入了该特定目标,但是现在出现以下错误:
I am trying to use the MSBuild Community Tasks target in my build. This target exists in source control. So in my csproj file i am import that particular target but i now get the following error:
错误MSB4062:无法从程序集C:\ Program Files(x86)\ MSBuild \ MSBuildCommunityTasks \ MSB加载"MSBuild.Community.Tasks.Attrib"任务 uild.Community.Tasks.dll.无法加载文件或程序集'file:///C:\ Program F iles(x86)\ MSBuild \ MSBuildCommunityTasks \ MSBuild.Community.Tasks.dll'或以下之一 它的依赖关系.该系统找不到指定的文件.确认 声明是正确的,表明程序集及其所有依赖项 可用,并且该任务包含实现Micros的公共类 经常使用.Build.Framework.ITask. [C:\ SampleTest \ SampleTest.csproj]
error MSB4062: The "MSBuild.Community.Tasks.Attrib" task could not be loaded from the assembly C:\Program Files (x86)\MSBuild\MSBuildCommunityTasks\MSB uild.Community.Tasks.dll. Could not load file or assembly 'file:///C:\Program F iles (x86)\MSBuild\MSBuildCommunityTasks\MSBuild.Community.Tasks.dll' or one of its dependencies. The system cannot find the file specified. Confirm that the declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Micros oft.Build.Framework.ITask. [C:\SampleTest\SampleTest.csproj]
这是我的代码:
<Import Project="..\..\Builds\Common\MSBuildTasks\MSBuild.Community.Tasks\MSBuild.Community.Tasks.Targets" />
<Target Name="BeforeBuild">
<PropertyGroup>
<MyService>ServiceName</MyService>
</PropertyGroup>
<ServiceController ServiceName="$(MyService)" Action="Stop" />-->
</Target>
对以上内容有何想法?
当我在项目文件中指定dll时,为什么MSBuild会尝试在其他地方查找dll?
Why is MSBuild trying to look for the dll elsewhere when i have specified it in the project file?
预先感谢
I think the problem comes from within the MSBuild.Community.Tasks.Targets file - it is this file that actually references the MSBuild.Community.Tasks.dll
assembly.
如果打开文件,您会看到一堆UsingTask
元素,例如:
If you open the file you can see a bunch of UsingTask
elements, such as:
<UsingTask AssemblyFile="$(MSBuildCommunityTasksLib)" TaskName="MSBuild.Community.Tasks.Attrib" />
$(MSBuildCommunityTasksLib)
属性在文件顶部定义为:
The $(MSBuildCommunityTasksLib)
property is defined at the top of the file as:
<PropertyGroup>
<MSBuildCommunityTasksPath Condition="'$(MSBuildCommunityTasksPath)' == ''">$(MSBuildExtensionsPath)\MSBuildCommunityTasks</MSBuildCommunityTasksPath>
<MSBuildCommunityTasksLib>$(MSBuildCommunityTasksPath)\MSBuild.Community.Tasks.dll</MSBuildCommunityTasksLib>
</PropertyGroup>
因此,看起来您需要在调用<Import>
之前设置$(MSBuildCommunityTasksPath)
属性.
So it looks like you need to set the $(MSBuildCommunityTasksPath)
property before calling <Import>
.